May 1, 2012 at 1:08 pm
Iv seen this done multiple ways but i cant remember them sadly,
Im use to doing
Select Firstname, Surname, Age, HairColour, EyeColour
From Persons
where Firstname = 'Mark'
Can someone show me another way of doing this? I think it starts with Where <something> in
Im not sure......
May 1, 2012 at 1:11 pm
.Netter (5/1/2012)
Iv seen this done multiple ways but i cant remember them sadly,Im use to doing
Select Firstname, Surname, Age, HairColour, EyeColour
From Persons
where Firstname = 'Mark'
Can someone show me another way of doing this? I think it starts with Where <something> in
Im not sure......
Would help to know what it is you are trying to accomplish.
May 1, 2012 at 1:12 pm
Purely another way of doing it
May 1, 2012 at 1:17 pm
If all you are looking for is 'Mark' then the way you are doing it is the correct way.
May 1, 2012 at 1:24 pm
I was just curious thats all, because i saw a select statement few months back that had a "in" in it, followed by brackets etc
May 1, 2012 at 1:25 pm
If you are that curious, have tried looking in Books Online? It is a very good reference for MS SQL Server.
May 1, 2012 at 1:27 pm
Iv spent the past 30 minutes browsing the new trying to find examples of different ways you can do a select statement etc but iv just come across one, its only small but it gives me the information i need 🙂
May 1, 2012 at 1:28 pm
Searching this can be of difficult if you don't know what you are looking for, which I suspect you probably a bit uncertain. Here is the BOL link for the WHERE clause. http://msdn.microsoft.com/en-us/library/ms188047%28v=sql.105%29.aspx
This should explain what you are asking plus a couple dozen other questions you didn't know you needed an answer for yet.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 1, 2012 at 1:31 pm
And I'm just curious why. Other than curiosity, what is there you are trying to accomplish?
May 1, 2012 at 1:31 pm
Thanks for the link ill take a look 😀
May 1, 2012 at 1:33 pm
IN is for when you have a list of things that you want to compare, not a single name. So if you wanted Mark, William and James, you could do this:
WHERE Name = 'Mark' OR Name = 'William' OR Name = 'James'
or you could do this:
WHERE Name IN ('Mark', 'William', 'James')
They are completely synonymous and are executed in exactly the same way.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply