Results 1 to 5 of 5

Thread: With issue.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    With issue.

    I implement a stored procedure like this:

    Code:
    ELSE IF (@Command = 'GETUSERS_NEWS') --newsletter
    		;With Emails As (SELECT u.Email, ROW_NUMBER() OVER (ORDER BY u.Email) AS RowNumber 
    			FROM Users u LEFT JOIN Notifications n ON u.Username = n.Username WHERE 
    			u.Suspend IS NULL AND u.IsDelete IS NULL AND (n.NewsLetter = @Alert OR n.NewsLetter IS NULL))
    			SELECT * FROM Emails WHERE RowNumber BETWEEN @RowStart AND @RowEnd
    BUt it keeps saying that there's an error syntax ';' the semicolon in front of With. If I ran it in the sql query, it's fine.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: With issue.

    Semicolons are used in a SqlCommand but not in SQL Server Management Studio. Just start a new statement on a new line.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: With issue.

    Can you provide an example? If i put that with statement outside of the IF statement, it works, but if not, then it throws that error - how do I resolve that?

  4. #4
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: With issue.

    Code:
    ELSE IF @Command = 'GETUSERS_NEWS'
    		With Emails As (SELECT u.Email, ROW_NUMBER() OVER (ORDER BY u.Email) AS RowNumber 
    			FROM Users u LEFT JOIN Notifications n ON u.Username = n.Username WHERE 
    			u.Suspend IS NULL AND u.IsDelete IS NULL AND (n.NewsLetter = @Alert OR n.NewsLetter IS NULL))
    			SELECT * FROM Emails WHERE RowNumber BETWEEN @RowStart AND @RowEnd
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: With issue.

    I think that what you're trying to do is associate a single block of code with the ELSE:
    Code:
    ELSE IF @Command = 'GETUSERS_NEWS'
    BEGIN
        -- blah, blah, blah
    END
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

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