Thursday, 27 February 2025

SQL Query Utilities

   SELECT 

    JSON_VALUE([Test], '$.Test1') AS ABC, 

    JSON_VALUE([Test], '$.Test2') AS MNO, 

    JSON_VALUE([Test], '$.Test3') AS XYZ, 

    Column4

FROM [dbo].[Table]

WHERE ISJSON([Test]) = 1 AND JSON_VALUE([Test], '$.Test1') IS NOT NULL

Group by  JSON_VALUE([Test], '$.Test2'), JSON_VALUE([DefinedData], '$.Test2'), JSON_VALUE([Test], '$.Test3'), Column4

''Distinct top query with group by

SELECT   distinct TOP (100) ([Value])

  FROM [dbo].[Test] 

  Where [Col1] in

  (Select Col1 FROM [dbo].[Test2] )

  And [Key] = 'Testing'

  group by [Value]


  Select Distinct Top(1) Col1 as Col1Name, Col2, Count(Col1) as Records, Col3 from cfo.Test Group By Col1, Col2, Col3 Order by Col3 Desc



Nested json:
Nested JSON Query:
 select col1, col2, col3, col4, col5, col6 from Tabl1  WITH (NOLOCK)
    where col3= 'Test' and Col4 = 'Test'
and JSON_VALUE(JSON_QUERY(data,'$.data."Output.Facility"'),'$[0].subId')=  'Test'
Order by Col1 Desc

No comments:

Post a Comment