Click here to Skip to main content
15,906,455 members
Home / Discussions / Database
   

Database

 
Questionwhich answer is right? Pin
mctramp1688-Sep-09 14:47
mctramp1688-Sep-09 14:47 
AnswerRe: which answer is right? Pin
Ashfield8-Sep-09 21:05
Ashfield8-Sep-09 21:05 
GeneralRe: which answer is right? Pin
Mycroft Holmes8-Sep-09 21:20
professionalMycroft Holmes8-Sep-09 21:20 
GeneralRe: which answer is right? Pin
Ashfield9-Sep-09 1:31
Ashfield9-Sep-09 1:31 
GeneralRe: which answer is right? Pin
Mycroft Holmes9-Sep-09 14:48
professionalMycroft Holmes9-Sep-09 14:48 
GeneralRe: which answer is right? Pin
mctramp1689-Sep-09 2:20
mctramp1689-Sep-09 2:20 
AnswerRe: which answer is right? Pin
Bassam Saoud9-Sep-09 10:58
Bassam Saoud9-Sep-09 10:58 
QuestionDynamic SQL Help Pin
Jammer8-Sep-09 10:51
Jammer8-Sep-09 10:51 
Hi All,

I'm having some troubles working on my first stored proc using dynamic SQL and I've hit a brick wall and can't work out what I'm doing wrong. I have two tables that are always the same structure, however I wish to write a re-useable stored proc to copy records to a new table based on some value comparison. I have this in my stored proc at the moment:

ALTER PROCEDURE [dbo].[sp_CopyFileScorerChanges] 
	-- Add the parameters for the stored procedure here
	@SourceTable NVARCHAR(100),
	@TargetTable NVARCHAR(100)
AS
BEGIN
    SET NOCOUNT ON;
	
    DECLARE @zSQL NVARCHAR(4000)

	SET @zSQL = N'INSERT INTO ' + @SourceTable  + '(
					[FilePath],
					[CurrentCategory],
					[CurrentSubCategory],
					[CurrentBpm],
					[OldCategory],
					[OldSubCategory],
					[OldBpm]
					) 
					SELECT 
						@FilePath,
						@CurrentCategory,
						@CurrentSubCategory,
						@CurrentBpm,
						@OldCategory,
						@OldSubCategory,
						@OldBpm
					FROM  ' + @TargetTable +
					'WHERE CurrentCategory <> OldCategory'
					
				
	EXEC( sp_ExecuteSQL @zSQL, N'@FilePath NVARCHAR(4000),	
								 @CurrentCategory NVARCHAR(100),
								 @CurrentSubCategory NVARCHAR(100),
								 @CurrentBpm INT,
								 @OldCategory NVARCHAR(100),
								 @OldSubCategory NVARCHAR(100),
								 @OldBpm INT',
								 @FilePath,	
								 @CurrentCategory, 
								 @CurrentSubCategory, 
								 @CurrentBpm, 
								 @OldCategory, 
								 @OldSubCategory, 
								 @OldBpm
		)
END


I'm currently getting a 'Incorrect syntax near 'sp_ExecuteSQL' - Expecting STRING, TEXT_LEX, VARIABLE or GLOBAL_VAR. I just want to call the stored proc with two table names, the source table and the target table.

Any help would be really appreciated.

Thanks,

Jammer
My Blog | Articles

AnswerRe: Dynamic SQL Help Pin
Mycroft Holmes8-Sep-09 12:29
professionalMycroft Holmes8-Sep-09 12:29 
GeneralRe: Dynamic SQL Help Pin
Jammer9-Sep-09 3:24
Jammer9-Sep-09 3:24 
GeneralRe: Dynamic SQL Help Pin
J4amieC9-Sep-09 3:30
J4amieC9-Sep-09 3:30 
GeneralRe: Dynamic SQL Help Pin
Mycroft Holmes9-Sep-09 12:36
professionalMycroft Holmes9-Sep-09 12:36 
QuestionReplication error sql server 2005 Pin
ME_Learner8-Sep-09 3:41
ME_Learner8-Sep-09 3:41 
Questionhow to give permission to an ip to connec to sql server 2005 which is not in the domain Pin
prasadbuddhika7-Sep-09 20:58
prasadbuddhika7-Sep-09 20:58 
AnswerRe: how to give permission to an ip to connec to sql server 2005 which is not in the domain Pin
Mycroft Holmes8-Sep-09 12:23
professionalMycroft Holmes8-Sep-09 12:23 
Questionlist of unmatched countries from multiple tables using sql server Pin
teja.murali6-Sep-09 20:13
teja.murali6-Sep-09 20:13 
AnswerRe: list of unmatched countries from multiple tables using sql server Pin
Mycroft Holmes6-Sep-09 20:46
professionalMycroft Holmes6-Sep-09 20:46 
AnswerRe: list of unmatched countries from multiple tables using sql server Pin
εїзεїзεїз6-Sep-09 20:47
εїзεїзεїз6-Sep-09 20:47 
QuestionProblem to configuring reporting services Pin
hdv2126-Sep-09 4:47
hdv2126-Sep-09 4:47 
QuestionIMPORT DBF File into SQL 2000 Pin
Member 46502876-Sep-09 0:33
Member 46502876-Sep-09 0:33 
AnswerRe: IMPORT DBF File into SQL 2000 Pin
εїзεїзεїз6-Sep-09 20:39
εїзεїзεїз6-Sep-09 20:39 
GeneralRe: IMPORT DBF File into SQL 2000 Pin
Member 46502877-Sep-09 0:31
Member 46502877-Sep-09 0:31 
GeneralRe: IMPORT DBF File into SQL 2000 Pin
εїзεїзεїз7-Sep-09 6:08
εїзεїзεїз7-Sep-09 6:08 
QuestionTrigger not firing in SQL Server 2000 Pin
debsoft755-Sep-09 19:29
debsoft755-Sep-09 19:29 
AnswerRe: Trigger not firing in SQL Server 2000 Pin
Abhishek Sur6-Sep-09 0:05
professionalAbhishek Sur6-Sep-09 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.