Setting 2 vars with one SELECT statement

  • Is there a way to set two variables with ONE select statement?

    Example:

    DECLARE @PartDescription varchar(36)

    DECLARE @UnitOfIssue varchar (4)

    DECLARE @ComponentPartNumber varchar(36)

    SET @ComponentPartNumber = '314-019'

    SET @PartDescription, @UnitOfIssue = (SELECT Description, UnitOfIssue FROM dbo.PartMaster WHERE PartNumber = @ComponentPartNumber)

    The above line does NOT work, but it is what I am basically trying to do.  I am trying to avoid two select statements.  Not really a big deal, but it would make it cleaner.  This is part of a stored procedure.

    Thanks,

    Jim Shipley

     

  • Hello Jim,

    You can write it as follows:

    Select @PartDescription = Description, @UnitOfIssue = UnitOfIssue FROM dbo.PartMaster WHERE PartNumber = @ComponentPartNumber

    Thanks and have a nice day!!!


    Lucky

  • Thanks!  I knew there must be an easy way.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply