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)
 Dynamic SQL

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-03-19 : 09:27:39
Larry writes "SQL Server Version 8.0
I tried the example below from 4Guys from Rolla :
CREATE PROCEDURE [dbo].[MyProc] @TableName varchar(15),
@FirstName varchar(50),
@LastName varchar(50)
AS

-- Create a variable @SQLStatement
DECLARE @SQLStatement varchar(255)

-- Enter the dynamic SQL statement into the
-- variable @SQLStatement
SELECT @SQLStatement = "SELECT * FROM " +
@TableName + "WHERE FirstName = '"
+ @FirstName + "' AND LastName = '"
+ @LastName + "'"

-- Execute the SQL statement
EXEC(@SQLStatement)

When I run: exec myproc 'PayEmpMain','STEPHANIE','AGNEW'

I get:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '='. Can you help me?"

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2007-03-19 : 09:27:39
I can see you need a space before the WHERE clause. Print out @SQLStatement and post it.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-19 : 09:30:39
I thought "Ask SQLTeam" retired?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2007-03-19 : 09:59:17
It's not accepting any new questions. These are the ones that were already in the queue. There's a post about it in the thread in the Site News forum.

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page
   

- Advertisement -