Posts

Showing posts from October, 2022

Group by in Sql server

Image
  Group by = merge all such column values that are same and show single row of that merged row.  The columns that are in SELECT list and Group by list should be same. Here any 2 rows[all column] values will be same so when u use group by it will return one row. Note : if any row's single column value is different with other row's single column value [i.e.  if any mismatch. See red round circle] then Groupby will return all rows in this case. It returns all the rows because : Till Resource column both rows has same values but since status/decision columns has different values. Group By will return all rows in such cases

Ranking Functions in Sql server

Image
 

Nvarchar in Sql server

  Declare @val nvarchar(1000) select @val = N'GFG में आपका स्वागत है' select @val as HindiLanguage Declare @val nvarchar(1000) select @val = N'ಮಾಹಿತಿ' select @val as kannadaLanguage

JOIN with Multiple tables

 select A.item_id,A.value as DocID,B.Value as FamilyID,C.value as SDO,D.* from [Item_Detail](nolock) A inner join [Item_Detail](nolock) B on A.item_id = B.item_id inner join [Item_Detail](nolock) C on A.item_id = C.item_id left outer join [Item_Detail](nolock) D  on A.item_id = D.item_id and D.attribute_id='FC0DAAD6-7820-4DA1-AA77-CCF7780038E9' --giving at where clause is ok untill unless there is an existing row in the table, if there is no row --then we wont get the desired result. So better to use 'AND D.attribute_id='FC0DAAD6-7820-4DA1-AA77-CCF7780038E9'' at 'ON CLAUSE' itself even --if there is some performance issue where A.item_id = '68687B00-A22D-48A8-83FF-00000536E871' and A.attribute_id = 'FAA27652-97E8-4FBA-88EB-C77EC82C4109' and C.attribute_id = '5F859754-9FC4-4072-A054-41BF40F21A3B' and B.attribute_id = '925412D0-7574-46A6-B3BA-4C1111549456'