Solved

Assign result set to scalar?

Posted on 2013-06-05
2
282 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now