Showing posts with label exec. Show all posts
Showing posts with label exec. Show all posts

Sunday, February 26, 2012

Help SQL

Friends,
How can i get the result from this SQL?
SET @.TB=' TB_CLIENTES '
SET @.SQL='select count(*) as QT from '+@.TB
EXEC (@.SQL)
Thanks
Leandro Loureiro dos Santos
Vitoria-ES / BRAZILThis is a multi-part message in MIME format.
--=_NextPart_000_029D_01C37D0F.8A6D5BB0
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Please do not multi-post. Answered in .programming.
-- Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"Leandro Loureiro dos Santos" <leandro@.email.com> wrote in message =news:epFD38SfDHA.164@.tk2msftngp13.phx.gbl...
Friends,
How can i get the result from this SQL?
SET @.TB=3D' TB_CLIENTES '
SET @.SQL=3D'select count(*) as QT from '+@.TB
EXEC (@.SQL)
Thanks
Leandro Loureiro dos Santos
Vitoria-ES / BRAZIL
--=_NextPart_000_029D_01C37D0F.8A6D5BB0
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

Please do not multi-post. =Answered in .programming.
-- Tom
---T=homas A. Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL =Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql
"Leandro Loureiro dos Santos" wrote in =message news:epFD38SfDHA.164@.t=k2msftngp13.phx.gbl...Friends,How can i get the result from this SQL?SET @.TB=3D' TB_CLIENTES ='SET @.SQL=3D'select count(*) as QT from '+@.TBEXEC (@.SQL)ThanksLeandro Loureiro dos SantosVitoria-ES / BRAZIL

--=_NextPart_000_029D_01C37D0F.8A6D5BB0--

help SP Code

I type Code in SP

Exec ('INSERT INTO XXX (A,B,C)

Select A,'Y8',C From YYY

GROUP BY A,B');

But it has error, Value 'ABC' not correct

Why, Thanks

William

Exce SP Code have error

Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'Y8'.

|||

Try this:

EXEC ('INSERT INTO XXX (A,B,C) Select A,''Y8'',C From YYY GROUP BY A,B');

Chris

|||

If you want to use the single quote (‘) with in the sql string you have to use the escape sequence.

Many languages support \ as escape sequential char. But in sql server the same char need to be repeated (twice).

Example:

Select @.a = 'Sql Server''s'

So you have to change your query as follow as,

Exec (

'INSERT INTO XXX (A,B,C)

Select A,''Y8'',C From YYY

GROUP BY A,B'

);