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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Pulling multiple fields into multiple local variab

Author  Topic 

HockeyFan
Starting Member

26 Posts

Posted - 2007-12-05 : 11:47:37
I'm wanting to do a single select (or set) and pull 3 fields from a table, into 3 local variables: something like:

Select LNAME as @LastName, FNAME as @FirstName, MNAME as @MiddleName from USERS WHERE ID = @ID

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-05 : 12:03:40
you can take like this:-
Select @LastName=LNAME ,@FirstName =FNAME ,@MiddleName= MNAME from USERS WHERE ID = @ID
Go to Top of Page

HockeyFan
Starting Member

26 Posts

Posted - 2007-12-05 : 12:07:48
I tried that. Got the following:

Incorrect syntax near ','
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-05 : 12:21:16
Is this being used as part of some other query?
Go to Top of Page

cr8nk
Yak Posting Veteran

77 Posts

Posted - 2007-12-05 : 12:21:27
Post your code.
Go to Top of Page

HockeyFan
Starting Member

26 Posts

Posted - 2007-12-05 : 12:27:34
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

ALTER FUNCTION [dbo].[UFN_NAME_FROM_USERNAME] (@LOGGEDDOMAINUSER varchar(50))
RETURNS bigint AS
BEGIN
DECLARE @ID bigint
Declare @Username varchar(20)
Declare @FullName varchar(80)
Declare @LastName varchar(25)
Declare @FirstName varchar(25)
Declare @MiddleName varchar(25)
Declare @i int

Select @i = charindex('\', @LOGGEDDOMAINUSER, 1)

if (@i > 1)
Begin
Set @Username = substring(@LOGGEDDOMAINUSER, @i+1,20)
Set @ID = dbo.FN_GET_USER_ID(@Username)
Select @LastName=LNAME ,@FirstName =FNAME ,@MiddleName= MNAME from USERS WHERE ID = @ID
print @LastName, @FirstName, @MiddleName
End
Return 0 -- to be removed after Donnie updates the case manager ids
--Return @ID
END
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-12-05 : 12:43:16
didn't think you could have a print inside a function



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

HockeyFan
Starting Member

26 Posts

Posted - 2007-12-05 : 12:46:19
I guess that's it. thanx
Go to Top of Page
   

- Advertisement -