dbTalk Databases Forums  

partnumber as string subtracts

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss partnumber as string subtracts in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default partnumber as string subtracts - 08-10-2006 , 06:51 AM






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!


Reply With Quote
  #2  
Old   
Roy Harvey
 
Posts: n/a

Default Re: partnumber as string subtracts - 08-10-2006 , 07:41 AM






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 Harvey
Beacon Falls, CT

On 10 Aug 2006 04:51:45 -0700, j.eeuwijk (AT) tycoelectronics (DOT) com wrote:

Quote:
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!

Reply With Quote
  #3  
Old   
AT
 
Posts: n/a

Default Re: partnumber as string subtracts - 08-10-2006 , 08:02 AM



Quote:
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.



Reply With Quote
  #4  
Old   
Roy Harvey
 
Posts: n/a

Default Re: partnumber as string subtracts - 08-10-2006 , 08:38 AM



Glad you got it working!

Yes, if you are going to build a complete text string you need to
embedd the quotes around the resolved string expression. In my
example the expression is resolved by the INSERT command. By building
the entire command string the expression was resolved before that, so
the INSERT ended up as VALUES(123-456).

Roy Harvey
Beacon Falls, CT

On 10 Aug 2006 06:02:14 -0700, j.eeuwijk (AT) tycoelectronics (DOT) com wrote:

Quote:
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.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.