Re: Multiple variables



On Thu, 14 Apr 2005 04:52:00 -0700, Andy wrote:

>Hi Hugo
>
>Thanks very much for this - I've not tried it yet as I think there might be
>a couple of typos that I want to confirm:
>
>You declare a variable called @codes, presumably all of my old instances of
>@code should now read @codes instead.

Hi Andy,

My bad - since I adapted the script to work for more than one code at
once, I thought it'd be best to change the variable name from @code to
@codes - but after changing the first, I promptly forgot to change the
rest. <blush>


>Is the N in this line correct: SET @code = N'(12345,6789)'?

Yes. I've changed the datatype to nvarchar (note: not just varchar, but
nvarchar), as is required for dynamic SQL. The N in fron of the string
constant means that this is also regarded as nchar data instead of plain
char data. (Nothing bad will happen if you leave out the N, nor if you
use character type varchar - but it will cuase SQL Server to do an
implicit conversion under the hood. I prefer to use explicit conversion,
or no conversion at all).


>I'm not brave enough to give it a go anyway!!!

Always test code suggestions on a test database. Make sure you have a
recent backup or another means to retore the data. And if possible,
enclose the code to be tested in a transaction, so that you can rollback
the changes if something goes awry.

Following the above advise for code you write yourself is not exactly a
bad idea either :-)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
.



Relevant Pages

  • Re: Multiple variables
    ... "Hugo Kornelis" wrote: ... > use character type varchar - but it will cuase SQL Server to do an ... > implicit conversion under the hood. ... > Always test code suggestions on a test database. ...
    (microsoft.public.sqlserver.mseq)
  • Re: conversion
    ... >Is there some simple conversion or I have to use string function len and ... Hi Simon, ... Best, Hugo ... (Remove _NO_ and _SPAM_ to get my e-mail address) ...
    (microsoft.public.sqlserver.programming)