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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 creating field

Author  Topic 

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-09 : 21:30:29
Hi all. Hiw can i create a field in a query?

/*
table - HrSetTaxTable

taxpaytype taxcode salrate1 salrate2 basetax perover
A A1 1000 200 100 5
B A2 2000 300 90 5
B A3 3000 400 80 5
A A4 4000 500 70 5
C A5 5000 600 60 5
B A6 6000 700 50 5
C A7 7000 800 40 5

*/

How could I add another field(varchar type) named TTP.
If taxpaytype is equal to A, TTP = Daily
If taxpaytype is equal to B, TTP = Weekly
If taxpaytype is equal to C, TTP = Monthly

so my expected result.
/*
taxpaytype taxcode salrate1 salrate2 basetax perover TTP
A A1 1000 200 100 5 Daily
B A2 2000 300 90 5 Weekly
B A3 3000 400 80 5 Weekly
A A4 4000 500 70 5 Daily
C A5 5000 600 60 5 Monthly
B A6 6000 700 50 5 Weekly
C A7 7000 800 40 5 Monthly

*/

Thanks.
-Ron-

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-09 : 21:40:29
[code]
select taxpaytype, taxcode, salrate1, salrate2, basetax, perover,
TTP = case taxpaytype
when 'A' then 'Daily'
when 'B' then 'Weekly'
when 'C' then 'Monthly'
else ''
end
from HrSetTaxTable
[/code]


KH

Go to Top of Page
   

- Advertisement -