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.
Author |
Topic |
Suhi100
Starting Member
14 Posts |
Posted - 2015-02-18 : 06:24:55
|
Hello,Can someone explain and possibly give and example on what SELECT NULL means and how it works?I often see this expression in views for example,e select NULL as field_nameThanks |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-02-18 : 09:54:10
|
SELECT NULL means return no value. SELECT NULL as field_name means return no value and call it field_name |
|
|
Suhi100
Starting Member
14 Posts |
Posted - 2015-02-18 : 12:58:20
|
Thanks Gerald,and what is the practical use of it? Is it used to check if there are rows in a table or view? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2015-02-18 : 13:10:14
|
quote: Originally posted by Suhi100 Thanks Gerald,and what is the practical use of it? Is it used to check if there are rows in a table or view?
We'd need to see the code to be able to tell you why it is being done.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-02-18 : 13:10:57
|
Say you want to populate a table with default data, you might writeinsert into mytable (a, b, c)select 1, NUll, 2if you want to purposefully put no data in column b, perhaps for some particular test cases.It's not hard to think up other uses as well. I often see it as a placeholder in a UNION:select a,b,c from abc_dataunion allselect d, e, null from de_datasince the union operator requires the same number (and types) of columns for all rowsets |
|
|
Suhi100
Starting Member
14 Posts |
Posted - 2015-02-19 : 04:09:35
|
It makes sense as I saw it in a UNION operator so as I understand it is because the number of columns have to match.Thanks for the answers it is clear now |
|
|
|
|
|
|
|