samedi 30 juillet 2016

Hide One column while displaying in Excel sheet

I have a query whose result is fetched as an attachment in the Excel sheet. Now what I want is,

I want to hide RAName column while displaying in the excel sheet.

So what I want is, Can I hide that in sql query.

Below is my query.

SELECT                  
       row_number() over (order by (UserName)) as SR_No,        
       UserName,
       Doc_No Inward_No,  
       Document_Type Doc_Type,
       Party_Name,           
       Ref_No,      
       doc_date Inward_Date,
       Ref_date Dept_Received_Doc_Date,       
       Last_Action_date Last_status_update_date,
       Remarks,

       RAName                   
       FROM #MainTempTable                  
       order by UserName,RAName

NOTE: Please ignore the temp table part.

vendredi 29 juillet 2016

Sql group by yesterday's 9am to today's 9pm

50  2016-07-29 04:40:44.000
70  2016-07-29 04:40:33.000
30  2016-07-29 03:50:56.000
15  2016-07-28 00:03:16.000
74  2016-07-28 23:38:18.000
15  2016-07-28 23:30:11.000
7   2016-07-28 23:22:37.000
10  2016-07-28 21:02:19.000

How can i achieve to group yesterday and today?

I must see only one row,

271  2016-07-28

Thanks for any idea.

How to toggle between two values of concurrent table rows in sql

I have a table name [NavBar] with these columns:

Id [int]
Name [nvarchar]
DisplayOrder [int]

Sample data:

Id   Name   DisplayOrder
---------------------------
 100   Home        1
 101   Products    2
 103   Contact     3
 104   Career      4

How do I perform update operation to toggle between two rows DisplayOrder of two concurrent rows (order by Displayorder) ?

For example Contact = 4, Career = 3

Expected output:

100  Home      1
101  Products  2
102  Contact   4
103  Career    3

Input parameter: Id of one row only

How to Toggle between two values from table rows in Sql

I have a table name [NavBar] with these columns:

Id [int]
Name [nvarchar]
DisplayOrder [int]

Sample data:

Id   Name   DisplayOrder
---------------------------
 1   Home        1
 2   Products    2
 3   Contact     3
 4   Career      4

I want to write a query to update DisplayOrder between two rows.

For example Contact = 4, Career = 3

Expected output:

1  Home      1
2  Products  2
3  Contact   4
4  Career    3

How do I perform update operation to toggle between two rows display order ?

Input parameter: Id of one row only

Group parents with same children

I have a table like this

ID  Type                    ParentID
1   ChildTypeA              1
2   ChildTypeB              1
3   ChildTypeC              1
4   ChildTypeD              1

5   ChildTypeA              2 
6   ChildTypeB              2
7   ChildTypeC              2

8   ChildTypeA              3 
9   ChildTypeB              3
10  ChildTypeC              3
11  ChildTypeD              3

12  ChildTypeA              4
13  ChildTypeB              4
14  ChildTypeC              4

and I want to group parents that have same children - meaning same number of children of same type.

Example of my output would be:

Config Group    ParentID
ConfigA         1   
ConfigA         3   
ConfigB         2
ConfigB         4

I have no idea where to even begin.

jeudi 28 juillet 2016

How to sum dynamic columns in sql?

Assume I have a table with 3 columns. Is there possible sum of each column without specifying name of the column? And is there possible create a table with dynamic name of the column, and then sum of each column?

mercredi 27 juillet 2016

How to get count of availible guid from a comma separated string of guid

Declare @i int;
declare @stringOfGuids nvarchar(max)='''70173C2D-0B8E-4043-BD14-665D5DCCF112'',''B0B7445C-DF50-4D49-BD4E-B74958FB0618''
,''70173C2D-0B8E-4043-BD14-665D5DCCF112''';

as i have above string and here i need to count number of availible guid which is three. how can i get it in a Integer varible

Something like this ??

select @i= count(@stringOfGuids)

but it gives me 1 , need three as available guids are 3