Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Jannette
Starting Member
26 Posts |
Posted - 2011-08-30 : 09:15:02
|
The following query is giving an error, can you help ?Can you order by 2 fields in the ROW_NUMBER() expresssion?=================================================================SELECT (case when client_address.client_address_id = client.client_address_id then 0else 1end) as main_id , '"'+CLIENT.Client_Code+'"', ROW_NUMBER() OVER (PARTITION BY CLIENT_CODE ORDER BY CLIENT_CODE, main_id) AS Address_Number, '"'+CLIENT.Client_Name+'"', '"'+ADDRESS.Line_1+'"', '"'+ADDRESS.Line_2+'"', '"'+ADDRESS.Line_3+'"', '"'+Town.Description+'"', '"'+County.Description+'"', '"'+Address.Postcode+'"', '"'+Country.Description+'"', '"'+CLIENT_ADDRESS.Invoice_YN+'"', '"'+CLIENT_ADDRESS.Site_YN+'"'FROM CLIENTJoin CLIENT_ADDRESS on CLIENT.Client_Id = CLIENT_ADDRESS.Client_Id Inner join ADDRESS on CLIENT_ADDRESS.Address_Id = ADDRESS.Address_ID Inner Join TOWN On ADDRESS.Town_Id = TOWN.Town_Id Inner Join COUNTY On ADDRESS.County_Id = COUNTY.County_Id Inner Join COUNTRY On ADDRESS.Country_Id = COUNTRY.Country_IdORDER BY CLIENT_NAME, CLIENT_CODE, main_id |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-30 : 09:56:14
|
i didnt understand the purpose of concatenating all these quotes, but anyways if you want to do this you need to CAST all the non varchar fields to varchar like '"'+ CAST(CLIENT.Client_Code AS varchar(10))+'"'...Your ROW_NUMBER looks fine . as per current logic it groups by CLIENT_CODE and within group numbers them as per order of main_Id. Not sure what else you're expecting. can you elaborate?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|