July 11, 2013 at 11:35 pm
i have problem while selecting table_name
ABC
2abab
2bcbc
3acac
4asas
this is my table and i want to execute
select * from table_name
only when it has more than 2 rows.
if count(*) table_name 2 i dont want to print table_name.
for this i tried
SELECT
CASE (SELECT COUNT(*) FROM table_name) WHEN 2 THEN "Min Row Cond not valid"
ELSE (SELECT * FROM table_name AS abc )
END
but i am getting
Error Code : 1241
Operand should contain 1 column(s)
how to solve this problem
thank you
July 11, 2013 at 11:50 pm
Use the same technique as you get from the answers in your previous post http://qa.sqlservercentral.com/Forums/Topic1472563-391-1.aspx
Replace the "SELECT CASE" into an "IF" statement.
July 12, 2013 at 2:31 am
Judging from the error message, you are not using SQL Server. Which product do you use?
[font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]
July 12, 2013 at 3:39 am
IF (SELECT COUNT(*) FROM table_name) > 2
BEgin
SELECT * from Table_name
END
ELSE
BEGIn
Print 'Min Row Cond not valid'
END
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
July 12, 2013 at 7:52 am
Your other thread on the same topic had the answers as they are for sql server. Since you are using MySql you may have to do it slightly differently. This is a sql server forum and the answers you will receive are related to that product. If you need specific syntax help for MySql you really need to find a forum dedicated to it.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply