question

ChrisThomas avatar image
ChrisThomas asked

Using Commas is SELECT statement

Apologies if I am missing something obvious here If I execute the following Select statement select Sequence, LS_Config_Name, PFDavg, LambdaD, HwareFaultTolID, SafeFailFractID from LogicSolver order by ID where all columns in the select list are separated by a comma, then the results set returned shows me all columns However if I execute the following statement select Sequence LS_Config_Name, PFDavg, LambdaD, HwareFaultTolID, SafeFailFractID from LogicSolver order by ID where there is no comma between the Sequence field and the LS_Config_Name field then the statement will execute but the results set will not contain the Sequence field If I take this a bit further and try to execute the following statement select Sequence LS_Config_Name PFDavg, LambdaD, HwareFaultTolID, SafeFailFractID from LogicSolver order by ID where there is no comma separating the Sequence and LS_Config_Name fields, nor is there a comma separating the LS_Config_Name and the PFDavg field, then I get an error Can you explain why the second statement works but misses out the Sequence field, while the third statement fails.
selectcomma
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
ThomasRushton avatar image
ThomasRushton answered
The second statement works because it is interpreted as SELECT Sequence AS LS_Config_Name... So if you look at your resultset from query 2, you'll see that you *do* have the Sequence data, but it's under a column called "LS_Config_Name". Consider this code: DECLARE @foobar TABLE ( foo VARCHAR(MAX) , bar VARCHAR(MAX) , baz VARCHAR(MAX) ); INSERT INTO @foobar VALUES ( 'foo', 'bar', 'baz' ); SELECT foo , bar , baz FROM @foobar; SELECT foo bar , baz FROM @foobar; The results are: foo bar baz ------------ ------------ ------------ foo bar baz bar baz ------------ ------------ foo baz
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ChrisThomas avatar image ChrisThomas commented ·
Thomas Thanks for the response. I didn't think of that. When I was looking at the Results Set I was not looking at the data returned otherwise I may have spotted this. I only noticed that I did not have as many columns as expected Cheers
1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.