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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Sql Question

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-06-05 : 08:35:37
Rajdett writes "Dear Sir,

I am using asp.net with database sql 7.0 .

I am retreiving data from a table roy

This table has a column called DataValue which has data like
0
-1
-2

I have to display data in datagrid(asp.net) on condition

If 0 Display Inclusive
If -1 Display Not Applicable
If -2 Display As Applicable

I want to know how to write If Else condition with sql query to display this in a asp.net Datagrid.

Thanks"

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-06-05 : 08:53:53
Roy is a good name for a table.

You would use a case statement for this :



SELECT

CASE DataValue
WHEN 0 THEN 'Inclusive'
WHEN -1 THEN 'Not Applicable'
WHEN -2 THEN 'Applicable' END as DataValueText

FROM MyTableRoy





Damian
Go to Top of Page

mtomeo
Starting Member

30 Posts

Posted - 2003-06-05 : 08:55:23
I think this is what you are looking for...Case works better than If...Then in this situation. You can also add an "Else" condition for all other values.

Note: I'm assuming DataValue is numeric. Add quotes if it's a string.


Select
Case DataValue
When 0 Then 'Inclusive'
When -1 Then 'Not Applicable'
When -2 Then 'As Applicable'
End
From roy


Go to Top of Page
   

- Advertisement -