I wanted to have a temporary table that will insert values using select statements. But every time I ran the query, I always got error
Subquery returns more than 1 value. This is not permitted when the query follows =, !=, <, <=, >, >=, or when the subquery is used as an expression. The statement has been terminated. (0 row(s) affected)
It's weird cause it seems there's no errors in the code. But if there is, please correct me.
Here's the query:
DECLARE @tblKeywords TABLE (Keyword1 VARCHAR(MAX), Keyword2 VARCHAR(MAX), Keyword3 VARCHAR(MAX))
Insert into @tblKeywords (Keyword1, Keyword2, Keyword3)
Values(
(Select k from
(Select Keyword k, ROW_NUMBER() OVER (ORDER BY KeywordID) AS RowNum from t_SMSKeyword) as mytable
where mytable.RowNum BETWEEN 1 and 3),
(Select kk from
(Select Keyword kk, ROW_NUMBER() OVER (ORDER BY KeywordID) AS RowNum from t_SMSKeyword) as mytable
where mytable.RowNum BETWEEN 4 and 6),
(Select kkk from
(Select Keyword kkk, ROW_NUMBER() OVER (ORDER BY KeywordID) AS RowNum from t_SMSKeyword) as mytable
where mytable.RowNum BETWEEN 7 and 9)
)
Select * from @tblKeywords
In SQLServer2005+ You can use option with common table expression
See example on SQLFiddle
Select 4 rows in the first column and 3 rows for the other columns
Example for second solution SQLFiddle
You'll get your desired result with the following query
SQLFIDDLE
try this