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
 IsDefault column

Author  Topic 

madhan
Yak Posting Veteran

59 Posts

Posted - 2015-01-17 : 10:31:39
Hi - I am new to sql server and floowing sql server 2008 bible book. the book says

in the OBXKites database,one CustomerType is the default for new customers and is set to true in the IsDefault column.

I am not sure in the database CustomerType table where it is set. Could you please let me know how to use/set isDefault. Thanks

madhan
Yak Posting Veteran

59 Posts

Posted - 2015-01-17 : 10:40:47
There is an Default column defined for CustomerType table. That sample data is

0
0
1

Is the column what the author mean as IsDEfault? if so how is the case statement used like this

USE OBXKites;
SELECT CustomerTypeName,
CASE IsDefault
WHEN 1 THEN ‘default type’
WHEN 0 THEN ‘possible’
ELSE ‘-’
END AS AssignStatus
FROM CustomerType;

I am confused. how did they place the IsDefault condn for case expression.
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-01-17 : 11:09:20
That's a short form for:

CASE WHEN IsDefault = 1 THEN 'default type'
WHEN IsDefault = 0 THEN 'possible'
ELSE '-'
END
Go to Top of Page

madhan
Yak Posting Veteran

59 Posts

Posted - 2015-01-17 : 11:20:45
Thanks for the reply. Does that mean if we have Default column defined in table, for case expression we can define the column as IsDefault?
Go to Top of Page

madhan
Yak Posting Veteran

59 Posts

Posted - 2015-01-17 : 11:32:50
Sorry, not clear on my earlier reply.

Does that mean if we have default column defined in table then for case expression we can use IsDefault=someValue? What if I don't define default column in table then we can't use IsDefault=someValue in case expression?
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-01-17 : 11:52:29
In your query the case statement refers to a column named IsDefault. So, if there IS no such column, you cannot refer to it.

so the answer to your last question is "No, you can't use it in the case expression, since it is not defined"
Go to Top of Page

madhan
Yak Posting Veteran

59 Posts

Posted - 2015-01-17 : 12:18:41
Thanks, But the Table defined column name is "Default" not
IsDefault.
Go to Top of Page
   

- Advertisement -