Thursday, March 22, 2012

calculated field in SQL 2000

I need a calculated field C with several CASES.
If (field A is 'daily' or 'half day' or 'hourly') and (field B is NULL) then C= D-50
If (field A is hourly and field B is NULL then C= 850
I don't know sql server 2000 well enough to create this query.
thanks
Milton

Are you trying to create a calculated column in a table or you need a SELECT query with this calculation?

|||

I need a SELECT query or view.

thanks
Milton

|||

Check out the CASE statement in Books On Line. Its pretty much self explanatory. They have illustrated it with some sample code too.

|||

I need to know the web site. I looked up books on line and found many sites with that URL. booksonline, books-on-line etc. none that I looked through were free and non had sql 2000.

|||

Here.. Its absolutely free..http://technet.microsoft.com/en-us/sqlserver/bb428874.aspx check the language you want to download it in on the right..

|||

miltonsnider:

I need a calculated field C with several CASES.
If (field A is 'daily' or 'half day' or 'hourly') and (field B is NULL) then C= D-50
If (field A is hourly and field B is NULL then C= 850
I don't know sql server 2000 well enough to create this query.
thanks
Milton

give it a try as start...

SELECT CASE WHEN (A LIKE 'hourly' AND B IS NULL) THEN 850 -- If (field A is hourly and field B is NULL then C= 850
WHEN (A LIKE 'daily' OR A LIKE 'half day' OR A LIKE 'hourly') AND (B IS NULL) THEN D - 50 END--If (field A is 'daily' or 'half day' or 'hourly') and (field B is NULL) then C= D-50
AS 'C'
FROM TBL_TABLE1

(without Comment)

SELECT CASE WHEN (A LIKE 'hourly' AND B IS NULL) THEN 850
WHEN (A LIKE 'daily' OR A LIKE 'half day' OR A LIKE 'hourly') AND (B IS NULL) THEN D - 50 END
AS 'C'
FROM TBL_TABLE1

hope you get some idea...

No comments:

Post a Comment