Friday, February 17, 2012

Dynamic Sql limit

I am trying to set up an Sql Statement that will run at various times of the
day automatically. I have to use a Dynamic string and am getting an error:
Server: Msg 103, Level 15, State 7, Line 3
The identifier that starts with 'Select distinct
Rank=0,l.CompanyID,m.UserID,
FullName= Case When (ResumeConfidential=0 and HideNameS=1) or
(ResumeConfidential' is too long. Maximum length is 128.
My code is something like:
Declare @.Search VarChar(8000)
Select @.Search = "Select distinct Rank=0,l.CompanyID,m.UserID,
...
Execute(@.Search)
GO
How do I get around this limitation?
My string could be 1000 characters long or more.
Thanks,
TomUse ' not " to delimit strings.
"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:OetZFxMMGHA.3272@.tk2msftngp13.phx.gbl...
>I am trying to set up an Sql Statement that will run at various times of
>the day automatically. I have to use a Dynamic string and am getting an
>error:
> Server: Msg 103, Level 15, State 7, Line 3
> The identifier that starts with 'Select distinct
> Rank=0,l.CompanyID,m.UserID,
> FullName= Case When (ResumeConfidential=0 and HideNameS=1) or
> (ResumeConfidential' is too long. Maximum length is 128.
> My code is something like:
> Declare @.Search VarChar(8000)
> Select @.Search = "Select distinct Rank=0,l.CompanyID,m.UserID,
> ...
> Execute(@.Search)
> GO
> How do I get around this limitation?
> My string could be 1000 characters long or more.
> Thanks,
> Tom
>|||"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:u$FUL2MMGHA.2316@.TK2MSFTNGP11.phx.gbl...
> Use ' not " to delimit strings.
How do I do that if my string has single quotes in it?
For example:
Select @.Search = 'Select distinct Rank=0,l.CompanyID,m.UserID,
Category = Case when Len(Category) > 22 then substring (Category,1,22) +
'...' else Category end
...'
Thanks,
Tom

>
>
> "tshad" <tscheiderich@.ftsolutions.com> wrote in message
> news:OetZFxMMGHA.3272@.tk2msftngp13.phx.gbl...
>|||"tshad" <tscheiderich@.ftsolutions.com> wrote in message
news:eeALK7MMGHA.3936@.TK2MSFTNGP10.phx.gbl...
> "Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in
> message news:u$FUL2MMGHA.2316@.TK2MSFTNGP11.phx.gbl...
> How do I do that if my string has single quotes in it?
Got it.
I just add another single quote next to each single quote and it works fine.
Thanks,
Tom
> For example:
> Select @.Search = 'Select distinct Rank=0,l.CompanyID,m.UserID,
> Category = Case when Len(Category) > 22 then substring (Category,1,22)
> + '...' else Category end
> ...'
> Thanks,
> Tom
>
>

No comments:

Post a Comment