Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Select variable1=top 1 column_name from tablename

Shows Error
Posted

Try:
SQL
DECLARE @ID INT
SET @ID = (SELECT TOP 1 MyColumn FROM MyTable ORDER BY MyColumn)
PRINT @ID
 
Share this answer
 
Comments
vidhyankr 12-Sep-14 0:07am    
This solution is working.Thanks for the help
OriginalGriff 12-Sep-14 3:26am    
You're welcome!
its a syntax error try this
SQL
--assuming ur value type is varchar
declare @a varchar(50)
SELECT TOP 1 @a=MyColumn FROM MyTable ORDER BY MyColumn
SELECT @a
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900