ExamNotes.net  -  IT certification portal

ForumsCertResearchTop sitesNewslettersFree email
HomeRegister


Exams Notes
Practice exams
Exam games
Questions by email
Online training
Training videos
College degrees
Boot camps
Book store
Links directory
Tell a friend
For webmasters




General discussions > Public newsgroups > microsoft.public.sqlserver.server > @variable,TSQ_string delitmiter problem?

Show a Printable Version
Email This Page to Someone!
Receive updates to this thread



Author @variable,TSQ_string delitmiter problem?
Dan Egan
Guest




Registered: Not Yet
Location:
Country:
State:
Certifications:
Working on:

Total Posts: N/A
@variable,TSQ_string delitmiter problem?

I always like to post answers if I find them first. I
used the SET QUOTED_IDENTIFIER OFF so that I could use the
double quotation marks when building my string. Here is
the result

SET QUOTED_IDENTIFIER OFF

DECLARE @TARGET VARCHAR(50)
DECLARE @NAME VARCHAR(50)
DECLARE @SQLCMD VARCHAR(200)

SET @TARGET = 'DataProcessDB'
SET @NAME = 'DataProcessDB_Data'
SELECT @SQLCMD = "USE " + @TARGET + ";SELECT * FROM
sysfiles WHERE name = '" + @NAME + "'"

EXEC(@SQLCMD)


>-----Original Message-----
>Hello everyone,
>
>I was hoping someone could help me with delimiting a
>tsql_string with a where clause.
>Below is an example of what I am trying to do.
>
>DECLARE @TARGET VARCHAR(50)
>DECLARE @NAME VARCHAR(50)
>
>SET @TARGET = 'DataProcessDB'
>SET @NAME = 'DataProcessDB_Data'
>
>EXEC ('USE ' + @TARGET + ';SELECT size,maxsize,growth

FROM
>sysfiles where name = '' + @NAME + ''')
>
>The returned results are empty when I know this to be
>incorrect. Any recommendations.
>
>TIA
>
>.
>

Report this post to a moderator

Old Post 10-08-02 01:23 AM
Reply w/Quote Edit/Delete Message IP: Logged
Ron Talmage
Guest




Registered: Not Yet
Location:
Country:
State:
Certifications:
Working on:

Total Posts: N/A
Re: @variable,TSQ_string delitmiter problem?

Dan,

Actually, you just need a couple extra quote marks. The following works with
the pubs sample database:

DECLARE @TARGET VARCHAR(50)
DECLARE @NAME VARCHAR(50)

SET @TARGET = 'Pubs'
SET @NAME = 'Pubs'

EXEC ('USE ' + @TARGET + ';SELECT size,maxsize,growth FROM
sysfiles where name = ''' + @NAME + '''')

You're better off not using the double-quote to terminate a string, as it's
not ANSI standard SQL.

Ron
--
Ron Talmage
SQL Server MVP


"Dan Egan" <DanielJEgan@hotmail.com> wrote in message
news:27d201c26e5e$a578be10$39e
f2ecf@TKMSFTNGXA08...
> I always like to post answers if I find them first. I
> used the SET QUOTED_IDENTIFIER OFF so that I could use the
> double quotation marks when building my string. Here is
> the result
>
> SET QUOTED_IDENTIFIER OFF
>
> DECLARE @TARGET VARCHAR(50)
> DECLARE @NAME VARCHAR(50)
> DECLARE @SQLCMD VARCHAR(200)
>
> SET @TARGET = 'DataProcessDB'
> SET @NAME = 'DataProcessDB_Data'
> SELECT @SQLCMD = "USE " + @TARGET + ";SELECT * FROM
> sysfiles WHERE name = '" + @NAME + "'"
>
> EXEC(@SQLCMD)
>
>
> >-----Original Message-----
> >Hello everyone,
> >
> >I was hoping someone could help me with delimiting a
> >tsql_string with a where clause.
> >Below is an example of what I am trying to do.
> >
> >DECLARE @TARGET VARCHAR(50)
> >DECLARE @NAME VARCHAR(50)
> >
> >SET @TARGET = 'DataProcessDB'
> >SET @NAME = 'DataProcessDB_Data'
> >
> >EXEC ('USE ' + @TARGET + ';SELECT size,maxsize,growth

> FROM
> >sysfiles where name = '' + @NAME + ''')
> >
> >The returned results are empty when I know this to be
> >incorrect. Any recommendations.
> >
> >TIA
> >
> >.
> >



Report this post to a moderator

Old Post 10-08-02 06:23 AM
Reply w/Quote Edit/Delete Message IP: Logged
All times are GMT.
Post new thread   Post reply


Forum Jump:
Rate This Thread:
Forum Rules:
Who Can Read The Forum? Any registered user or guest.
Who Can Post New Topics? Any registered user.
Who Can Post Replies? Any registered user.
Changes: Messages can be edited by their author.
Posts: HTML code is OFF. Smilies are ON. vB code is ON. [IMG] code is OFF.
 

ExamNotes forum archive


Powered by: vBulletin 2.2.8
Copyright ©2000, Jelsoft Enterprises Limited.

  Free Braindumps | mcse braindumps