jesh Posted January 9, 2007 Share Posted January 9, 2007 I have to perform some logic in a stored procedure based on the values in a particular table. I know that I can do this to assign some values to two variables: DECLARE @value1 intDECLARE @value2 intSET @value1 = (SELECT column1 FROM mytable WHERE id=5)SET @value2 = (SELECT column2 FROM mytable WHERE id=5) Does anyone know whether or not I can do the above with a single select statement rather than having to run two selects against the same table to fetch two different columns in the same row?DBMS is SQL Server 2005. Link to comment Share on other sites More sharing options...
pulpfiction Posted January 9, 2007 Share Posted January 9, 2007 Try this, it should work....DECLARE @value1 int, @value2 intSELECT @value1 = column1, @value2 = column2 FROM mytable WHERE id=5 Link to comment Share on other sites More sharing options...
aspnetguy Posted January 9, 2007 Share Posted January 9, 2007 try this DECLARE @value1 intDECLARE @value2 intSELECT @value1 = column1, @value2 = column2FROM mytable WHERE id=5 Link to comment Share on other sites More sharing options...
jesh Posted January 9, 2007 Author Share Posted January 9, 2007 Excellent! Thanks guys. Link to comment Share on other sites More sharing options...
aspnetguy Posted January 9, 2007 Share Posted January 9, 2007 wow how did I not see your post pulp...beat me to it Link to comment Share on other sites More sharing options...
pulpfiction Posted January 9, 2007 Share Posted January 9, 2007 Neither did I see you.... may be it did not show us in a dotted underline [replying...] there's a big time diff.. wierdMine: 12:18 AMYours: 12:26 AM Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now