Re: Dynamic column specification in table update
From: Tibor Karaszi (tibor_please.no.email_karaszi_at_hotmail.nomail.com)
Date: 10/06/04
- Next message: Laura: "Index utilisation statistics"
- Previous message: William \(Bill\) Vaughn: "Re: Poor VB Programming"
- In reply to: Alec MacLean: "Re: Dynamic column specification in table update"
- Next in thread: Tibor Karaszi: "Re: Dynamic column specification in table update"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 6 Oct 2004 18:49:11 +0200
Yes, you need braces to EXEC a string. Again print the string to you know what you are trying to
execute. A varchar can be up to 8000 if declare properly. If you need more, you can use below
technique:
EXEC (@str1 + @str2)
-- Tibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://www.solidqualitylearning.com/ "Alec MacLean" <alec.maclean@NO-SPAM-copeohs.com> wrote in message news:%23r%23vTO8qEHA.2580@TK2MSFTNGP15.phx.gbl... > Changing the EXEC to include braces round the sql command variable helps (partially): > > SELECT @DSQL = 'UPDATE #tRes SET [' + CAST(@H AS NVARCHAR(30)) + ']' > SELECT @DSQL = @DSQL + > <snip blah> > ... > > EXEC ( @DSQL ) > > But then I get Error 170 (incorrect syntax). The output string is the first 256 chars of the DQL > string, which happens to be on the 'W' of the where clause... > Is the 256 truncation a factor of the error message processing (so a non-factor), or a limit of > QA? > > Thanks > > Al > > "Alec MacLean" <alec.maclean@NO-SPAM-copeohs.com> wrote in message > news:eXcVzG8qEHA.3244@tk2msftngp13.phx.gbl... >> Thanks Mal... >> >> I've not used Dynamic SQL before, so been reading up a bit. >> I've tried your suggestion, but I get the server message 203 ("name is not a valid identifier") >> > <snip> >> >> Thanks for your help. >> >> Al >> >> > >
- Next message: Laura: "Index utilisation statistics"
- Previous message: William \(Bill\) Vaughn: "Re: Poor VB Programming"
- In reply to: Alec MacLean: "Re: Dynamic column specification in table update"
- Next in thread: Tibor Karaszi: "Re: Dynamic column specification in table update"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|