![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I'm trying to write a DTS package that sends some partnumbers from one table to another. The partnumbers are something like xxxxx-y, so for example you could have 12345-6. When I insert the partnumbers into the new table, the following happens: Instead of 12345-6 I find in my table the value 12339; the two numbers are substracted. My insert statement looks something like this: INSERT INTO table VALUES (@basenumber + '-' +@suffix) Both variables are VARCHAR. Should I use some special character instead of using the - character? Or should I switch from VARCHAR to another type? Thanks! |
#3
| |||
| |||
|
|
Roy Harvey wrote: I put together a simple test: declare @basenumber varchar(10), @suffix varchar(10) set @basenumber = '123' set @suffix = '456' select (@basenumber + '-' +@suffix) create table Whatever (x varchar(30)) INSERT Whatever values (@basenumber + '-' +@suffix) select * from Whatever x ------------ 123-456 The only explanation that comes to mind a that something is different between the code sample given and the actual code treating the process as arithmetic rather than concatenation. |
#4
| |||
| |||
|
|
Roy Harvey wrote: I put together a simple test: declare @basenumber varchar(10), @suffix varchar(10) set @basenumber = '123' set @suffix = '456' select (@basenumber + '-' +@suffix) create table Whatever (x varchar(30)) INSERT Whatever values (@basenumber + '-' +@suffix) select * from Whatever x ------------ 123-456 The only explanation that comes to mind a that something is different between the code sample given and the actual code treating the process as arithmetic rather than concatenation. Roy, I tried your simple test and it worked flawlessly. The only difference I could find is that I wrote the INSERT as a text string into a variable called @query. Later on in my script I executed the query using EXEC @query. I changed my script so the insert was no longer in this variable and the problem was solved... Thanks! Joost. |
![]() |
| Thread Tools | |
| Display Modes | |
| |