This query executes just fine as-is. However, SQL Management Studio won't save it as a view because I define a variable.
DECLARE @HighestTransaction int SET @HighestTransaction = (SELECT MAX(CardID) FROM dbo.Transactions) SELECT Uploads.*, Transactions.* FROM Uploads LEFT OUTER JOIN dbo.Transactions ON dbo.Uploads.Code = dbo.Transactions.CardID WHERE (Uploads.Code > CASE WHEN @HighestTransaction IS NULL THEN -1 ELSE @HighestTransaction END)
I haven't really played around with stored procedures, or user defined functions a whole lot, so I'm not sure of the best way to go about doing this. Or, if there's a better way to write this, I'm open to suggestions as well.