sql server - join table and where column similar to other column, while changing column value SQL -
i have issue code. sql issue.
i need combine 2 tables. @ present have code:
select calldate,clid, '44'+dst [numberdialed],dstchannel,billsec,disposition,accountcode,uniqueid,cnam, callrateimport.description, callrateimport.code, callrateimport.day calllogimport left join callrateimport on calllogimport.dst callrateimport.code + '%' callrateimport.code(select code callrateimport calllogimport.dst code + '%' , len(code) = (select max(len(code)) callrateimport calllogimport.dst callrateimport.code + '%') )
this combining fine. need match altered result depending on original result is.
i have code:
if substring (dst,1,2)=00 begin end
wrapping current code. sql throwing errors - incorrect syntax. have else if block of 3 components.
to modify values based on current value, should @ case statements.
for example:
use adventureworks2012; go select productnumber, category = case productline when 'r' 'road' when 'm' 'mountain' when 't' 'touring' when 's' 'other sale items' else 'not sale' end, name production.product order productnumber; go
or searched case expressions:
use adventureworks2012; go select productnumber, name, "price range" = case when listprice = 0 'mfg item - not resale' when listprice < 50 'under $50' when listprice >= 50 , listprice < 250 'under $250' when listprice >= 250 , listprice < 1000 'under $1000' else 'over $1000' end production.product order productnumber ; go
Comments
Post a Comment