Sunday, June 13, 2021

How to get list of column names from Table Variable @table

A table variable is a variable data type which can be used to store temporary data. It's defined using the DECLARE keyword and the table's structure is defined in the declaration as shown below:

declare @ns_source table
(
  col1_id int, 
  col2_name varchar(50),
  col3_desc varchar(50)
)    

Unlike temporary tables, table variables are not affected by a rollback. As regular variables, they keep the data which was modified during the transaction even if the transaction is rolled back.

Coming to get columns from table varaiable, here is how we can get using below query.

declare @ns_source table
(
  col1_id int, 
  col2_name varchar(50),
  col3_desc varchar(50)
)

select DP.N.value('local-name(.)', 'sysname') as ColumnName
from 
  (
  select NS.*
  from (select 1) as D(N)
    outer apply (
                select top(0) *
                from @ns_source
                ) as NS
  for xml path(''), elements xsinil, type
  ) as LV(X)
cross apply LV.X.nodes('*') as DP(N)

Result looks like below





Wednesday, June 02, 2021

How can we bulk close issues on JIRA?

Here is how we can bulk close JIRAs

Step 1: Search all the issues/stories you wan to close (Using JQL or predefined filter of your own),  something like below.




Step 2: Choose the issues that needs to be closed.

Step 3: Choose Operation, Since we are closing, we need to select transition issues and go to next. 

Step 4: Choose the operation from available workflow actions







Step 5: Here I have choosed Resolved as i am closing these issues.

Step 6: Select Resolved and proceed further.









Step 7: Add comments (optional) and choose resolution













Step 8: Choose confirm to bulk close all the tickets.










Easy right!!

Tuesday, June 01, 2021

Visual Studio 2019 Tips and Tricks

Visual Studio 2019 has a new feature with visibility into how an external library or dependency resource is handling the data you are giving it can provide valuable insight. Debugging decompiled resources is a great feature that allows to step into external libraries.

Select Tools > Options. Type “decompile” into the search bar. The Advanced section of Text Editor for C# will appear. Click on Advanced.
  

Check the box that says Enable navigation to decompiled sources (experimental).

Now you can debug and step into the external packages you pull in from Nuget and elsewhere! 

Happy Debugging!!

Saturday, May 29, 2021

How to Get Columns details from SQL Tables

Here is how you can get column names from specified table

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns 
WHERETABLE_NAME = 'MobilityOrders'

Here is how you can get column count from specified table

SELECT COUNT(COLUMN_NAME) as COUNT FROM INFORMATION_SCHEMA.Columns 
WHERE TABLE_NAME = 'MobilityOrders'

Here is how you can get column count from temp table

 SELECT COUNT(*) as Cnt FROM tempdb.sys.columns
 WHERE object_id = object_id('tempdb..#temp2')

Hope this helps 😀

Friday, May 21, 2021

How to: Looping through reader count dynamically C#

Here is how this can be done once you have the data call via Read methods
   
using (var reader = await sqlDbContext.ExecuteReaderAsync(command))
{
   
    while (await sqlDbContext.ReadAsync(reader))
    {
        // when count greaterthan 1
        if (reader.FieldCount > 1)
        {
            if (!string.IsNullOrEmpty(reader["ItemD"].ToString()))
            {
                mobilityChangeOrdersItem.ItemID= reader["ItemID"] == null ? 0 : Convert.ToInt32(reader["ItemID"].ToString());
            }
            if (!string.IsNullOrEmpty(reader["ID"].ToString()))
            {
                mobilityChangeOrdersItem.ID = reader["ID"] == null ? 0 : Convert.ToInt32(reader["ID"].ToString());
            }
        }
    }

    //Looping through complete list of return variables to find out requrired column
    string errorMessge = " SQL Message: -- *Start* ItemD -- :: " + mobilityChangeOrdersItem.ItemD;
    while (await reader.NextResultAsync())
    {
        var fieldvalues = Enumerable.Range(0, reader.FieldCount).Select(i => reader.GetName(i)).ToArray();

        while (await reader.ReadAsync())
        {
            if (fieldvalues.Contains("ErrorMessage"))
            { 
                errorMessge += Environment.NewLine + " ErrorMessage : " + reader["ErrorMessage"].ToString();
            }
            if (fieldvalues.Contains("ErrorProcedure"))
            {
                errorMessge += Environment.NewLine + " ErrorProcedure : " + reader["ErrorProcedure"].ToString();
            }
        }
        errorMessge += Environment.NewLine + " SQL Message: -- *End*";
        mobilityChangeOrdersItem.StatusMessage = errorMessge;
    } 
    mobilityChangeOrdersList.Add(mobilityChangeOrdersItem);
}

Hope this helps 😀