Reputation:
I'm writing a database query where I want to get the id number of the folder into the @eFolderID
variable
DECLARE @eFolderId varchar(30)
SET @eFolderId = NULL
SELECT TOP 1 *
FROM ProcessSupportMap
SET @eFolderId = EFOLDERID
WHERE Number = 'B0261109'
I want:
SET @eFolderId = EFOLDERID WHERE Number = 'B0261109'
I don't know where to put it
Upvotes: 0
Views: 50
Reputation: 29943
You should use SELECT @local_variable statement to set a local variable to the value of an expression:
DECLARE @eFolderId varchar(30)
SELECT TOP 1 @eFolderId = EFOLDERID
FROM ProcessSupportMap
WHERE Number = 'B0261109'
Additional notes:
Upvotes: 1
Reputation: 164064
You can assign the value returned by the subquery to the variable:
SET @eFolderId = (
SELECT TOP 1 EFOLDERID
FROM ProcessSupportMap
WHERE Number = 'B0261109'
)
Upvotes: 0