Click here to Skip to main content
15,942,545 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
[no name] 22-Dec-12 2:30am    
will you please elaborate?
[no name] 22-Dec-12 2:34am    
ya, sure!!!

In short how can we store value of query in STORE PROCEDURE.
[no name] 22-Dec-12 2:35am    
you understand my problem?

Change
@No=select max(no) from reg_table

to
SQL
select @No = max(no) from reg_table

That should resolve your issue.
 
Share this answer
 
Comments
[no name] 22-Dec-12 5:21am    
Thank You Dear ,


Thx again.
__TR__ 22-Dec-12 6:15am    
You're welcome.
this will also help
SQL
select @No = max(no) from reg_table
insert into table values('1','101',@No);

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

Happy Coding!
:)
 
Share this answer
 
Comments
[no name] 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! :)
[no name] 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
[no name] 22-Dec-12 5:40am    
ya, m using 2008 :)

NOW what to DO?

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