|
-
Jun 2nd, 2011, 10:10 PM
#1
Thread Starter
Frenzied Member
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.
-
Jun 2nd, 2011, 11:31 PM
#2
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.
-
Jun 3rd, 2011, 03:25 PM
#3
Thread Starter
Frenzied Member
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?
-
Jun 3rd, 2011, 05:14 PM
#4
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
-
Jun 3rd, 2011, 10:43 PM
#5
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|