Solved

select [value] into [variable] from [table]

Posted on 2006-07-18
6
478 Views
Last Modified: 2008-02-01
hi,

how is it possible to achieve something like this?

select min(RowId) into @minRowId from @t1

where @t1 is the table variable and @minRowId is the INT variable
0
Comment
Question by:davidlars99
6 Comments
 
LVL 25

Expert Comment

by:Mr_Peerapol
ID: 17133101
select @minRowId = min(RowId)  from @t1
0
 
LVL 20

Assisted Solution

by:Sirees
Sirees earned 200 total points
ID: 17133104
Try this

select @minRowId = min(RowId) from @t1
0
 
LVL 13

Author Comment

by:davidlars99
ID: 17133123
I did and it didn't work. I'll try again when I get home.


Thanks!
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 25

Accepted Solution

by:
Mr_Peerapol earned 200 total points
ID: 17133245
I think what you mean is that @t1 is a varchar variable that holds a table name. If it is, you need a dynamic sql like this:

DECLARE @t1 VARCHAR(100)
DECLARE @minRowId INT
DECLARE @sql NVARCHAR(1000)

SET @sql = N'SELECT @minRowId = MIN(RowId) FROM ' + @t1
EXEC sp_executesql @sql ,
     N'@minRowId INT OUTPUT', @minRowId OUTPUT

SELECT @minRowId
0
 
LVL 7

Assisted Solution

by:LandyJ
LandyJ earned 100 total points
ID: 17133299
In order to get Output parameters from Dynamic SQL you have to use sp_ExecuteSQL as in:
How to specify output parameters when you use the sp_executesql stored procedure in SQL Server
http://support.microsoft.com/default.aspx?scid=kb;en-us;262499
0
 
LVL 7

Expert Comment

by:LandyJ
ID: 17133339
Forgot to add: Here's a link to MSDN example that explains Mr_Peerapol's response.  

No points for me.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question