SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Select clause SQL Quary


Select clause SQL Quary

Author
Message
saurabhvashistha
saurabhvashistha
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 15
Lets Create a table
Create Table test(Name varchar(50), SalaryAmount money)
insert into test(Name, SalaryAmount) values(A, 10000)
insert into test(Name, SalaryAmount) values(b, 11000)
insert into test(Name, SalaryAmount) values(d, 110000)
insert into test(Name, SalaryAmount) values(f, 10000)
insert into test(Name, SalaryAmount) values(g, 9800)
insert into test(Name, SalaryAmount) values(h, 10000)
insert into test(Name, SalaryAmount) values(k, 8000)
insert into test(Name, SalaryAmount) values(l, 10000)
insert into test(Name, SalaryAmount) values(n, 15000)

Now i Have to write a query which give me result like if Salary is greater then or equal to 10000 grade A else b like
Result should be

Name Grade
A A
b A
d A
f A
g b
h A
k b
l A
n b

How do I accomplish this can anyone suggest
Dave Ballantyne
Dave Ballantyne
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6724 Visits: 8370
By using the case statement

select ....,case when money >=10000 then 'A' else 'B' end as Grade
from ....



Clear Sky SQL
My Blog
saurabhvashistha
saurabhvashistha
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 15
Can you Please provide a query for getting that result...
Dave Ballantyne
Dave Ballantyne
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6724 Visits: 8370
I dont wish to be rude , but if that is causing you troubles you really need to go on a course.



Clear Sky SQL
My Blog
saurabhvashistha
saurabhvashistha
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 15
Yes Sir i understand that, but i am in urgent need for the query as i am facing issues in developing that, i am new to SQL and i am in learning phase. So Please do help if u can...
Ian Scarlett
Ian Scarlett
SSCarpal Tunnel
SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)

Group: General Forum Members
Points: 4992 Visits: 7136
... or if it's homework, you need to do a bit more studying.:-D



Dave Ballantyne
Dave Ballantyne
SSCertifiable
SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)SSCertifiable (6.7K reputation)

Group: General Forum Members
Points: 6724 Visits: 8370
Take a look at Books Online

http://msdn.microsoft.com/en-us/library/ms130214.aspx



Clear Sky SQL
My Blog
saurabhvashistha
saurabhvashistha
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 15
Aha!!!!! I got Now i am able to create such queries :-) thanks for help.....
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search