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 |
Reprovo
Starting Member
8 Posts |
Posted - 2014-01-30 : 14:59:34
|
Hi. I'm trying to understand why I can enter a query such as: select 5,"random" from customers; and get two columns with 5 and "random" in every respective column field.Why don't I receive a syntax error ? |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2014-01-30 : 15:19:42
|
quote: Originally posted by ReprovoWhy don't I receive a syntax error ?
Not to be captain obvious, but I can only assume the syntax is valid. Meaning you have a column named Random in your table Customers.If you want the value "random" as a string, try using single quotes (') instead of double quotes ("). Double quotes are one way to specify a quoted identifier, which doesn't seem like what you want here. |
 |
|
Reprovo
Starting Member
8 Posts |
Posted - 2014-01-31 : 01:05:41
|
I don't have a table with "random".I can do the same with absolutely any string or number |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-31 : 07:45:08
|
quote: Originally posted by Reprovo I don't have a table with "random".I can do the same with absolutely any string or number
yes thats by designreason is simpleselect supports returning constant valueie SELECT 1,'Text value',102.5 etcthis can be utilized to populate table with mutiple values likeINSERT Table(COl1,Col2,Col3)SELECT 1,'Text value',102.5 UNION ALLSELECT 2,'Text value123',56.5... similarly you can intermix columns with constant values toolikeINSERT Table(COl1,Col2,Col3)SELECT 1,TextColumn,102.5 FROM Table2... so that it inserts constants 1 and 102.5 for 1st and 3rd columnswhereas it put actual column values from Table2 for column 2.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
Reprovo
Starting Member
8 Posts |
Posted - 2014-01-31 : 09:20:14
|
Ok that clears things up for me! Thanks |
 |
|
|
|
|
|
|