dbTalk Databases Forums  

Confused

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Confused in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
John
 
Posts: n/a

Default Confused - 08-18-2004 , 08:25 AM






Hello,

I was just wondering why this command:

select * from C_Update where lastname like '%,%'

works fine in query analyzer, but when used within the confines of an
execute sql task in this fashion:

DECLARE @CommaCheck nvarchar(4000)
SET @CommaCheck = 'select * from C_Update where lastname like '%,%''
EXEC @CommaCheck

It generates an error. The error pertains to the %,% area, but I can't
figure
out another way to rearrange the code w/o using the apostrophe. Make sense?
Also, I was digging through the net and found a very good page on dynamic
sql
in which it was mentioned that one should never use "select" in production
code...
Which is exactly what I'm doing. Rather confusing as a newbie dts
programmer.

Any help is thankfully appreciated!



Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Confused - 08-18-2004 , 03:38 PM






Your correct Query should be

DECLARE @CommaCheck nvarchar(4000)
SET @CommaCheck = 'select * from authors where au_lname like ''%,%'''
EXEC(@CommaCheck)

You were not terminating the string properly and

Exec @CommaCheck would have expected a stored Proc

--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.konesans.com - Consultancy from the people who know


"John" <jtaylor (AT) kmznet (DOT) com> wrote

Quote:
Hello,

I was just wondering why this command:

select * from C_Update where lastname like '%,%'

works fine in query analyzer, but when used within the confines of an
execute sql task in this fashion:

DECLARE @CommaCheck nvarchar(4000)
SET @CommaCheck = 'select * from C_Update where lastname like '%,%''
EXEC @CommaCheck

It generates an error. The error pertains to the %,% area, but I can't
figure
out another way to rearrange the code w/o using the apostrophe. Make
sense?
Also, I was digging through the net and found a very good page on dynamic
sql
in which it was mentioned that one should never use "select" in production
code...
Which is exactly what I'm doing. Rather confusing as a newbie dts
programmer.

Any help is thankfully appreciated!





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.