Results 1 to 9 of 9

Thread: [RESOLVED] Set parameter value in select statement

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Resolved [RESOLVED] Set parameter value in select statement

    Hello friend
    How we can set parameter value in select statement.


    Code:
    Declare @ID decimal(18,2)
    
    Select TOP 1 StudentId from Table1
    How I can set first column value in parameter @ID In stored procedure... can we do it without courser.
    Thanks
    Shakti


  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Set parameter value in select statement

    This?
    Code:
    SET @ID = Select TOP 1 StudentId from Table1
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Set parameter value in select statement

    I am getting error incorrect syntax error.


    Code:
    Declare @TotalAssessedValue decimal(18,2)
    
    SET @TotalAssessedValue = select TOP 1 totalassdval  from VTable order by CYear desc
    Last edited by shakti5385; Apr 1st, 2009 at 03:59 PM.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Set parameter value in select statement

    Erm.. what is that WHERE doing there?

  5. #5

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Set parameter value in select statement

    Thanks I had done that but still same problem

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Set parameter value in select statement

    Try it like this:
    Code:
    SET @TotalAssessedValue = (select TOP 1 totalassdval  from VTable order by CYear desc);

  7. #7

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Set parameter value in select statement

    thanks

    now if we have two parameter than?


    Code:
    SET @TotalAssessedValue1,@TotalAssessedValue2 = (select TOP 1 A,B from VTable order by CYear desc);

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Set parameter value in select statement

    You must use the Select statement to set multiple local variables at once

    Select TOP 1 @TotalAssessedValue1 = A, @TotalAssessedValue2 = B from VTable order by CYear desc

  9. #9

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Set parameter value in select statement

    Thanks I got that

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width