Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 sp_executesql

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-01-09 : 08:25:57
Alin writes "Hello.
I have a question for you.
I am using sql server 7. I have a stored procedure called top_client with 3 parameters (firm,datai,dataf). I want to execute this procedure using sp_executesql and I dont know how.
I would apreciate any help. thank you."

Pumkin
Starting Member

20 Posts

Posted - 2006-01-09 : 09:03:19
DECLARE @sql nvarchar(100)
SET @sql=N'EXEC dbo.top_client '''firm''','''datai''','''dataf''''
EXEC dbo.sp_executesql @sql
Go to Top of Page

Pumkin
Starting Member

20 Posts

Posted - 2006-01-09 : 09:10:13
I'm really sorry for that. A little corection. I seem to put too many quotes. :P

DECLARE @sql nvarchar(100)
SET @sql=N'EXEC dbo.top_client ''firm'',''datai'',''dataf'''
EXEC dbo.sp_executesql @sql

That will work fine.
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-01-09 : 10:06:08
Sorry for stating the obvious but I just want to make sure you know:
To execute a stored procedure in sql server, you don't have to use "sp_executesql".

From a Query Analyzer window you can simply:

exec <spname> [parameter=value parameter list]

Be One with the Optimizer
TG
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-09 : 11:32:54
Can't this be done without exec part ?

I mean using
SPName para1, para2 --> execute in QA ?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-01-09 : 12:45:45
Yes, but only if the statement is run as a single statement, and not as a block of statements.

I always put the EXEC in so I don't forget when its a Block rather than a Singleton!!

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-10 : 01:24:29
quote:
Originally posted by Srinika

Can't this be done without exec part ?

I mean using
SPName para1, para2 --> execute in QA ?



Yes
But if you need to execute more than one sp then you need to use Go to seperate them

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-10 : 10:02:58
Thanks Kristen & Madivanan
Go to Top of Page
   

- Advertisement -