Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Error in String Concatenation
Message
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Error in String Concatenation
Divers
Thread ID:
00673923
Message ID:
00673923
Vues:
59
While looping through a cursor, I'm getting an interger value 600 that I cast to a varchar. The value is really a starting time I am going to use later to append to a date, so I am trying to eventaully make it read '06:00' So I am checking the length and if it = 3, then I want to append the '0' in front. The problem is I'm getting an error message on the line where I add the zero. Without that line I get the print statement to print 600. The error message is:
Line 55: Incorrect syntax near '@tempString'.
Here is the code
set @addZero = '0'
-- Setup Cursor variables
declare @c_RoomName varchar(30)
declare @c_Length int
declare @c_DeptID int
declare @c_RoomID int
declare @c_StartTime int
declare @c_EndTime int

-- Loop Through the Cursor
while (@tiRoomCtr <= @tiRooms)
Begin
   fetch avail_Rooms into @c_RoomName,@c_Length,@c_DeptID,@c_roomID,@c_StartTime,@c_EndTime
   set @tiRoomCtr = @tiRoomCtr+1
   set @tempstring = cast(@c_StartTime as varchar(5))
   if len(@tempString) = 3
     BEGIN
        @tempString=@addZero + @tempString
     END
   print @tempstring
END 
Anybody know why?

Thanks
Kirk
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform