Click here to Skip to main content
15,912,457 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
I am use the function for generate Uniq No WardID+SerialNo
WardID Comes from table FamilyHead
SerialNo Save in FamilyMember
WardID     Uniq No Should be Generated
12         12000001,12000002,12000003 and so on..
13         13000001,13000002,13000003 and so on...
15         15000001,15000002,15000003 and so on....


I use this type logic it's not work properly
can you help please....

SQL
ALTER function [dbo].[fnFamilyUniqueID](@WardID int) returns table
as
RETURN
(

SELECT CONVERT(Varchar(15),CONVERT(varchar,@WardID) + 'W-') +
       CONVERT(varchar(6),dbo.fnFormatSerialNoPostfix

       (CONVERT(int,SUBSTRING(MAX(SerialNo),10,6)+1))
       FROM FamilyMember
       inner join FamilyHead on FamilyMember.FamilyID = FamilyHead.FamilyID
       WHERE FamilyHead.WardID=@WardID
}


Where dbo.fnFormatSerialNoPostfix is... generate the 6 digit no


SQL
ALTER Function [dbo].[fnFormatSerialNoPostfix]
(@SerialNo Int)
Returns varchar(10)
As
Begin

      return Right(Replicate('0',6)+Convert(Varchar(10),@SerialNo),6)

End
Posted
Updated 19-Aug-13 20:45pm
v2
Comments
Status BreakPoint 20-Aug-13 3:01am    
The error is "column name is not specified". So, I think that you should put column alias by "AS".

1 solution

just append
AS 'ID'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900