Click here to Skip to main content
13,086,019 members (86,320 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
hi frnds!!


i create store procedure for inset data into table.


@No=select max(no) from reg_table //select maximum no from other table
exec(@No)
insert into table values('1','101',@No);

i want to do this but @no not store result of query.

how can fetch NO and insert it into table???
Posted 21-Dec-12 20:28pm
Comments
sajeesh.c 22-Dec-12 2:30am
   
will you please elaborate?
DBKings 22-Dec-12 2:34am
   
ya, sure!!!

In short how can we store value of query in STORE PROCEDURE.
DBKings 22-Dec-12 2:35am
   
you understand my problem?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Change
@No=select max(no) from reg_table

to
select @No = max(no) from reg_table

That should resolve your issue.
  Permalink  
Comments
DBKings 22-Dec-12 5:21am
   
Thank You Dear ,


Thx again.
__TR__ 22-Dec-12 6:15am
   
You're welcome.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

this will also help
select @No = max(no) from reg_table
insert into table values('1','101',@No);

or
insert into table
select 
'1',
'101',
(Select max(no) from reg_table)

Happy Coding!
:)
  Permalink  
Comments
DBKings 22-Dec-12 5:22am
   
thx for solution.....but solved by above solution.
Aarti Meswania 22-Dec-12 5:27am
   
okay that's nice!
and Welcome! :)
Glad to help you! :)
DBKings 22-Dec-12 5:35am
   
:) okay.
can you help, how can debug Store Procedure?
i want to see value of variable belongs to SP.
Aarti Meswania 22-Dec-12 5:38am
   
you can do so if you are using sql 2008 but nope if it's lower version of sql
DBKings 22-Dec-12 5:40am
   
ya, m using 2008 :)

NOW what to DO?
Aarti Meswania 22-Dec-12 5:45am
   
write query click a play button press f10 for go on
visit link
http://msdn.microsoft.com/en-us/library/aa291255(v=vs.71).aspx
DBKings 22-Dec-12 5:56am
   
ok thx...
Aarti Meswania 22-Dec-12 6:01am
   
welcome! :) same as visual studio F11 and F10 is useful and you can put debug point using F9
DBKings 22-Dec-12 7:59am
   
ok :)
plz add me in Linked-In, i already send request.
Aarti Meswania 22-Dec-12 8:04am
   
okay it's you! I will
DBKings 22-Dec-12 8:06am
   
Thx

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 22 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100