Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Plz help me : a simple function

Author  Topic 

vedjha
Posting Yak Master

228 Posts

Posted - 2008-09-26 : 09:13:56
declare @name varchar(500)
declare @ids varchar(20)
set @ids='U100000000'

if exists (select @name=vastname from login where aid = @ids)
print @name
else
print 'Invalid ID'


Ved Prakash Jha

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-26 : 09:16:18
[code]declare @name varchar(500)
declare @ids varchar(20)
set @ids='U100000000'
select @name=vastname from login where aid = @ids
if @name is not null
print @name
else
print 'Invalid ID' [/code]
Go to Top of Page

vedjha
Posting Yak Master

228 Posts

Posted - 2008-09-26 : 09:17:57
Thanks ...

Ved Prakash Jha
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-26 : 09:20:16
[code]CREATE FUNCTION dbo.fnGetName
(
@IDs VARCHAR(20)
)
RETURNS VARCHAR(20)
AS
BEGIN
RETURN COALESCE((SELECT TOP 1 VastName FROM Login WHERE aID = @IDs), 'Invalid ID')
END[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -