SQL server: Order by multiple columns incorrect syntax -


i'm using sql server 2008.

select resulttable.ordernumber,                 resulttable.projectid,                 resulttable.batchid,                 resulttable.customerid,                 resulttable.city,                 resulttable.street,                 resulttable.postalcode,                 resulttable.country,                 resulttable.createddate,                 resulttable.name,                 count(*) over() orderscount,                 row_number() on                    (order                     case when @sortby = 'ordernumber'                     resulttable.ordernumber end,                     case when @sortby = 'projectid'                     resulttable.projectid end,                     case when @sortby = 'address'                     resulttable.country, resulttable.city, resulttable.street, resulttable.postalcode end,                     case when @sortby = 'createddate'                     resulttable.createddate end) rowindex resulttable 

this query fires syntax error near ","

then resulttable.country, resulttable.city, resulttable.street, resulttable.postalcode end, 

if remove columns after first "," ok, i'm trying sort address, consists of 4 columns. cannot see easy here.

ps: @sortby string parameter.

try this:

order    case when @sortby = 'ordernumber'      resulttable.ordernumber end,    case when @sortby = 'projectid'       resulttable.projectid end,    case when @sortby = 'address'      resulttable.country end,    case when @sortby = 'address'       resulttable.city end,     case when @sortby = 'address'       resulttable.street end,     case when @sortby = 'address'       resulttable.postalcode end,    case when @sortby = 'createddate'      resulttable.createddate end 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -