Solved

Incorrect syntax near the keyword 'where'.

Posted on 2011-02-13
6
375 Views
Last Modified: 2012-05-11
Hello,

I try to execute this script :
declare @sql1 varchar(max)
set @sql1 = 'delete from ['+@abonne + '].'+ @Db_ods + '.dbo.MSreplication_subscriptions'
where [publication] = '''+@publication+'''''
execute (@sql1)
print (@sql1)

Msg 156, Level 15, State 1, Procedure drop_repl, Line 84
Incorrect syntax near the keyword 'where'.

Thanks
bibi
0
Comment
Question by:bibi92
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:BurnieP
ID: 34883562
Hi, you have a non terminated string, you need to add the where part also.

set @sql1 = 'delete from ['+@abonne + '].'+ @Db_ods + '.dbo.MSreplication_subscriptions' + ' where [publication] = '''+@publication+''''

Might
0
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 34883583
declare @sql1 varchar(max)
set @sql1 = 'delete from ['+ @abonne + '].'+ @Db_ods + '.dbo.MSreplication_subscriptions
where [publication] = ''' + @publication + ''''
execute (@sql1)
print (@sql1)
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34883587
The single quotes before where is causing this error
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Closing Comment

by:bibi92
ID: 34883602
Thanks bibi
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34885224
Glad to help you
Raj
0
 
LVL 16

Expert Comment

by:BurnieP
ID: 34885238
I don't understand why my answer was not considerated, since I said the same thing Raj said, but 8 minutes earlier.

I guess it's the luck of the draw.

Cheers,
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question