Error when using WHILE Function in selecting on sQL server script
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Error when using WHILE Function in selecting on sQL server script

  1. #1
    Join Date
    Jul 2012
    Posts
    6

    Error when using WHILE Function in selecting on sQL server script

    hi guys i have this code,,

    Code:
    declare @n int
    set @n = 1
    SELECT     TOP 100 PERCENT ID, purchase_id, supp_add_mat_id, mat_code, asset_no, qty, require_by, require_date, require_desc, status, pr_detail_asset, 
                          scheduled, 
    		while @n <= 31
    		begin 
    	                CASE WHEN datepart(day, require_date) = @n THEN qty ELSE '0' END AS @n
    		set @n = @n+1
    		end 
    FROM         dbo.t_pr_details
    but the code is error coz i use the While function when selecting a data,,
    plz help..
    Last edited by ryanframes; July 23rd, 2012 at 12:57 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,301

    Re: Error when using WHILE Function in selecting on sQL server script

    Quote Originally Posted by ryanframes View Post
    ...
    but the code is error coz i use the While function when selecting a data,,
    plz help..
    Then remove (get rid of) this "While function"
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2012
    Posts
    6

    Re: Error when using WHILE Function in selecting on sQL server script

    Quote Originally Posted by VictorN View Post
    Then remove (get rid of) this "While function"
    no i want to use WHILE function when selecting a record set..
    but when i use it, it always shows error..

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,301

    Re: Error when using WHILE Function in selecting on sQL server script

    Quote Originally Posted by ryanframes View Post
    no i want to use WHILE function when selecting a record set..
    Where in the docs did you see WHILE loop within the SQL SELECT ... FROM query?

    Quote Originally Posted by ryanframes View Post
    but when i use it, it always shows error..
    It only means that either it is not allowed at all or you are using it wrong.
    Victor Nijegorodov

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center