Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Concatenating Two values

Author  Topic 

macca
Posting Yak Master

146 Posts

Posted - 2005-06-16 : 05:07:12
I have two values @service and @office in a stored procedure. When the stored procedure is running @service has the value P and @office has the value L. I want to asssign PL to @temp.
I have tried it the following way:
@temp = @service + @office
but the aove just gives @temp the value P, but does not add on the L.

Any Ideas.

Thanks,
macca

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-16 : 05:14:25
Declare @temp varchar(20)
Declare @service varchar(10)
Declare @office varchar(10)
set @service='P'
set @Office='L'
Set @temp = @service + @office
Select @temp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-06-16 : 05:27:02
quote:
Originally posted by macca
@temp = @service + @office



did you use a SET or SELECT command to assign the concatenated value to the @temp variable?



-ec
Go to Top of Page

macca
Posting Yak Master

146 Posts

Posted - 2005-06-16 : 06:07:08
Here is the code I am using:

CREATE PROCEDURE sproc_Macca
(
@serOff Char(4) OUTPUT
)

AS

DECLARE @Service char(4)
DECLARE @Office char(4)

SELECT @Service = Service, @Office = Office FROM Service WHERE DeptID = @deptID

SET @serOff = @Service + @Office

I have also tried using SELECT @serOff but it is also just returning P.
Go to Top of Page

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2005-06-16 : 06:50:22
use varchar instead of char
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-06-16 : 06:55:42
did you check the data size? 4 might not be enough, also declare @deptID

try:

CREATE PROCEDURE sproc_Macca
(@deptid varchar(10),
@serOff varchar(10) OUTPUT
)

AS


SELECT @Seroff = Service + Office FROM Service WHERE DeptID = @deptID




--------------------
keeping it simple...
Go to Top of Page

macca
Posting Yak Master

146 Posts

Posted - 2005-06-16 : 07:18:12
jen,

Thanks for the reply.
this is working but I am getting returned "P L ", there is a space between P and L and a space after L which is causing problems. Do you know how to get rid of the spaces.

macca
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-16 : 07:21:24
Use ltrim and rtrim


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

macca
Posting Yak Master

146 Posts

Posted - 2005-06-16 : 07:34:05
thanks madhivanan.
Go to Top of Page
   

- Advertisement -