Click here to Skip to main content
15,887,283 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys,
I have an problem
In My DSE(Executive)table There is Columns Like
FirstName
LastName
MiddleName
In my stored Procedure i have to concate the string as Full Name(May be temporary column)Si how i can achieve it.
I wrote SP..but dont knw its working or not

SP-
ALTER PROCEDURE dbo.GetDSEFullName
(
@FirstName varchar(50),
@MiddleName varchar(50),
@LastName varchar(50)
)

AS
BEGIN
Declare FullName varchar(500)
SET NOCOUNT ON
DECLARE @Err int
Declare @qry nvarchar(4000)
Declare @temp nvarchar(2000)


Set @temp = null

Set @qry ='
select
DSE_ID from DSE_Info
where DSE_Info.FirstName='''+@FirstName+''' and DSE_Info.LastName='''+ @LastName + ''''

if(@MiddleName is not null)
Begin
Set @temp = ' AND MiddleName = '''+ @MiddleName + ''''
Set @qry = @qry + @temp
SELECT
End

print @qry
Execute SP_EXECUTESQL @qry
SET @Err = @@Error

RETURN @Err

END
Posted
Comments
Azee 7-Oct-13 2:10am    
So you want your SP to return just the full name concatenated? You don't need an SP for that, just create a function and return concatenated full name.
indrajeet jadhav 7-Oct-13 2:14am    
How..will you help me ..This Full Name i need to bind Drop Down

Hey there,

I assume, the middle name could be null, so here is a scalar-valued function:
SQL
CREATE FUNCTION GetFullName
(
	@FirstName varchar(50),
	@MiddleName varchar(50),
	@LastName varchar(50)
)
RETURNS varchar(200)
AS
BEGIN
	DECLARE @FullName varchar(200) = @FirstName;
	IF (@MiddleName is NOT NULL AND @MiddleName <> '')
	BEGIN
		Set @FullName += ' ' + @MiddleName;
	END
	
	SET @FullName += ' ' + @LastName;
	RETURN @FullName

END


and here is how you can call it.
SQL
SELECT dbo.getFullName('John', 'J', 'Smith')


Hope it helps, do let me know.

Azee...
 
Share this answer
 
Awsomeee Work ..Azee ..Thnxx for your help
 
Share this answer
 
if (dtGetFullName.Rows.Count > 0)
{
for (int iCount = 0; iCount < dtGetFullName.Rows.Count; iCount++)
{
cmbDSEName.Items.Add(dtGetFullName.Rows[iCount]["DSE_FirstName"].ToString().Trim() + " " + dtGetFullName.Rows[iCount]["DSE_MiddleName"].ToString().Trim() + " " + dtGetFullName.Rows[iCount]["DSE_LastName"].ToString().Trim());
// cmbContactCode.Items.Add(dtSearchContacts.Rows[iCount]["ContactID"].ToString());
}
}
 
Share this answer
 
v2

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