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)
 Conversion of int to String and Concatenation

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-24 : 09:09:40
supriya writes "I am trying to convert an integer variable to char and then concatenate it with another string. Somehow this is not working.
the code is as follows

CREATE TRIGGER [InsertPrimary] ON [Categories]
FOR INSERT
AS
DECLARE @Primaryvalue int,
@Prefix char(2),
@PrimaryInsert char(3),
@strPrimaryValue char(2)

Select @PrimaryValue=Value, @Prefix=Prefix From KeyValues where TableName='Categories' and KeyName='CategoryID'

If @PrimaryValue=0
SET @PrimaryValue=1
Else
SET @PrimaryValue=@PrimaryValue+1


If @Prefix Is Null
Begin
SET @PrimaryInsert=@PrimaryValue
End
Else
Begin
SET @strPrimaryValue=STR(@PrimaryValue)
***SET @PrimaryInsert=RTRIM(@Prefix) + RTRIM(@strPrimaryValue)
End

Update Categories Set CategoryID=@PrimaryInsert where CategoryID='dum'
Update KeyValues Set Value=@PrimaryValue Where TableName='Categories' and KeyName='CategoryID'

the *** assignment is not working. I am expecting a string 'C0' but I only get 'C' not the zero. Whats wrong?"
   

- Advertisement -