SQL Server 2005 Setting a variable to the result of a select query

前端 未结 6 983
面向向阳花
面向向阳花 2021-02-05 00:31

How do I set a variable to the result of select query without using a stored procedure?


I want to do something like: OOdate DATETIME

SET OOdate =          


        
6条回答
  •  囚心锁ツ
    2021-02-05 00:50

    -- Sql Server 2005 Management studio

    
    use Master
    go
    DECLARE @MyVar bigint
    SET @myvar = (SELECT count(*) FROM spt_values);
    SELECT @myvar
    
    Result: 2346 (in my db)
    

    -- Note: @myvar = @Myvar

提交回复
热议问题