I have written this stored procedure for one my operations in the database, but it is prompting with two errors. I am fairly new top this, so it would be great if somebody could correct the mistake.
CREATE PROCEDURE findVersions
@seg nvarchar(255),
@str nvarchar(255)
AS
DECLARE @UnsegQuery AS nvarchar(255)
SET @UnsegQuery = SELECT DISTINCT UnsegmQuery
FROM tbData
WHERE SegQuery = @seg
SELECT TOP 1 Strategy, Versions, CGNum
FROM tbData
WHERE Strategy = @str
AND SegQuery = @seg
ORDER BY CGnum DESC
UNION
SELECT TOP 1 Strategy, Versions
FROM tbData
WHERE Strategy = 'BF'
AND UnsegmQuery = @UnsegQuery
UNION
SELECT Strategy, Versions
FROM (SELECT ROW_NUMBER() OVER (ORDER BY nDCG DESC) AS rownumber
FROM tbData) AS foo
WHERE rownumber > 1
Errors:
Msg 156, Level 15, State 1, Procedure findVersions, Line 10
Incorrect syntax near the keyword 'SELECT'.
Msg 156, Level 15, State 1, Procedure findVersions, Line 13
Incorrect syntax near the keyword 'UNION'
Any suggestions?
Update Eg: of what I have to do with the queries. I have to display the first result from the first query, first result from the second query and then the remaining three from the first query results.
1st class: (has 4 student)
Tom (Has highest score)
Rex (Hss second highest score)
Rambo (HAs 3rd highest score)
Betty (Has least score)
2nd class: (has 1 student)
Spooky (Has the highest score)
Required result order in DataControl:
Tom
Spooky
Rex
Rambo
Betty