Sqlserver Max with Over if you have alteast one entry in your table than this will be fastest Declare @tblMinMaxExample table ( pk integer not null identity(1,1) primary key, dataYearMonth integer, dataYear integer, dataMonth integer, recordedValue float, attributeA varchar(1), attributeB varchar(1) ) insert into @tblMinMaxExample values (201401, 2014, 1, 200.0, 'A', 'a') insert into @tblMinMaxExample select '201412', '2014', max(dataMonth) over(order by pk) , 100.0, 'L', 'l' from @tblMinMaxExample else use this Declare @tblMinMaxExample table ( pk integer not null identity(1,1) primary key, dataYearMonth integer, dataYear integer, dataMonth integer, recordedValue float, attributeA varchar(1), attributeB varchar(1) ) --insert into @tblMinMaxExample values (201...
Posts
Showing posts from 2018
- Get link
- X
- Other Apps
This is good example. CONVERT COLUMN VALUES TO COMMA SEPARATED ONE ROW VALUE I have a query the returns country....state...and cities the cities are creating ore rows than required, I need to re-write my query so that the cities column instead come in single row separated by commas... here is the data for more understanding CREATE TABLE [ dbo ].[ test12 ]( [ title ] [ varchar ]( 51 ) NULL , [ subtitle ] [ varchar ]( 52 ) NULL , [ value ] [ varchar ]( 53 ) NULL ) INSERT INTO test12 ( title , subtitle , value ) VALUES ( 'USA' , 'PA' , 'PHILLY' ) INSERT INTO test12 ( title , subtitle , value ) VALUES ( 'USA' , 'PA' , 'PITTSBURG' ) INSERT INTO test12 ( title , subtitle , value ) VALUES ( 'USA' , 'PA' , 'WARREN' ) INSERT INTO test12 ( title , subtitle , value ) VALUES ( 'USA' , 'PA' , 'UNION' ) INSERT INTO test12 ( title , subtitle...