Question : SQL Function Question

Two part question:

1) I am trying to write a function that returns a string based upon field values (see code snipit).  I think I have that part correct....   What is the statement to 'Returns'  - I just need it to be a string value based upon the selected Case.   I have a husband 1st name and last name and wife 1st and last name.    My Goal is one of the following (depending upon if any null values or different last names):

a)   Joe Smith
b)   Joe & Lisa Smith
c)   Joe Smith & Lisa Jones

2)  How do I use this function in a different Query?   For example.

Create Procedure ClientSearch @ID int
As
Select * from Client, GetName(@ID)
From Client

Thanks.


 
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Create Function GetName @ID int 
Returns ??????
 
AS
 
Select 
Case cSpouseName
 When Null Then cFirstName + '  ' + cLastName 
 Else 
    Case cSpouseLastName 
      When Null Then cFirstName + ' & ' + cSpouseName + ' ' + cLastName
      Else cFirstName + ' ' + cLastName 
      End
End  
 
FROM Client 
Where cClient = @ID

Answer : SQL Function Question

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Create Function GetName @ID int 
Returns VARCHAR(100)
 
AS
 
Select 
Case cSpouseName
 When Null Then cFirstName + '  ' + cLastName 
 Else 
    Case cSpouseLastName 
      When Null Then cFirstName + ' & ' + cSpouseName + ' ' + cLastName
      Else cFirstName + ' ' + cLastName 
      End
End  
 
FROM Client 
Where cClient = @ID
Random Solutions  
 
programming4us programming4us