Solved

Assign result set to scalar?

Posted on 2013-06-05
2
288 Views
Last Modified: 2013-06-05
I have a standard procedure where  MyNumber is passed in as a parameter.
Using it, I want to get the value of tblMyTable.MyId and assign it to @MyId
How do I do this?
 
DECLARE @Myid as int
select [Myid] from [MyDB].[dbo].[tblMyTable]
where [MyNumber] = @MyNumber
-- @MyId = [Myid] ???
-- use @Myid at this point

Open in new window

0
Comment
Question by:allelopath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 500 total points
ID: 39222125
DECLARE @Myid as int
select  @Myid = [Myid] from [MyDB].[dbo].[tblMyTable]
where [MyNumber] = @MyNumber
0
 
LVL 11

Expert Comment

by:Simone B
ID: 39222136
You have two variables used in your query, @Myid and @MyNumber. If you want to select from the table based on the passed-in variable only, then you don't need both.

DECLARE @MyNumber INT
SET @MyNumber = 12345

SELECT MyID, col1, col2, ..... FROM MyTable
WHERE MyID = @MyNumber

Open in new window

0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL 2012 AOG and SQL2014 AOG 76 61
add stored proc on publlication 4 20
Using datetime as triggers 2 24
Help with Progress 4gl Rounding Function 6 29
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

730 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