Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Concantenating Problem In Query
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01460836
Message ID:
01460844
Vues:
30
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform