Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Concantenating Problem In Query
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01460836
Message ID:
01460844
Views:
29
>>I'm trying to determine the next customer code using a 3 digit customer code. If you pass in "ABC", and there are already 3 rows for
>>customer ABC, then you should get bacl 'ABC-004'. Here's what I have:
>>
>>
>>
>>CREATE PROCEDURE ap_GetNextProjectNoForClient
>>	@CustomerCode	VARCHAR(03),
>>	@NewCustCode	VARCHAR(07) OUTPUT
>>	
>>AS
>>BEGIN
>>	
>>	DECLARE @Count INT
>>
>>	SELECT @Count = COUNT(CustomerCode)
>>		FROM COSProjects
>>		WHERE CustomerCode =  @CustomerCode
>>
>>	SET @NewCustCode = @CustomerCode + '-' + dbo.PADL(@Count, 3, '0')
>>
>>
>>
>>I'm calling it like this:
>>
>>DECLARE @Code VARCHAR(3)
>>EXEC ap_GetNextProjectNoForClient 'MCD', @Code OUTPUT
>>SELECT @Code
>>
>>
>>All I'm getting back is the @CustomerCode value.
>>
>>If I put this at the end, it works:
>>
>>
>>SELECT @CustomerCode + '-' + dbo.PADL(@Count, 3, '0')
>>
>
>Change this
>DECLARE @Code VARCHAR(3)
>>EXEC ap_GetNextProjectNoForClient 'MCD', @Code OUTPUT
>>SELECT @Code
>
>to
>
>DECLARE @Code VARCHAR(7)  -- new code should be varchar(7)
>EXEC ap_GetNextProjectNoForClient 'MCD', @Code OUTPUT
>SELECT @Code
>
>
>Also instead of dbo.PADL you can use
>
>SET @NewCustCode = @CustomerCode + '-' + right('000' + cast(@Count as varchar(3)), 3)
LOL. I gotta quit drinkin while I'm coding.

Thanks!
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Reply
Map
View

Click here to load this message in the networking platform