+ 1
Is there a alternative for TOP in sql
I have a sql query that uses TOP. "SELECT TOP 1 Id FROM Results where colum2=0" Every now and then the querry gives undefined results. Is there another way to get the first row in the table that meets the requirements ? Could the query be optimized ? I use sql.
3 ответов
+ 2
Yes, I use MSSQL. I get null back from the query.
command = new SqlCommand(SqlStr, conn);
reader = command.ExecuteReader();
try
{
while (reader.Read())
{
if (!reader.IsDBNull(0))
{
........
+ 2
Sneeze,
Does it work correctly if you remove the NULL check condition?
I've forgotten how, but did you check whether there was any record matching the query condition? I just thought about what happens when no match was found ...
+ 1
Hi Sneeze,
Can you elaborate further on that "gives undefined results" part? how it worked?
You are using MSSQL right? cause as I remember TOP is used by MSSQL only ...