473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Get count or find out has row

145 100+
I need to find out whether the following statement has any rows or not. Either by count>=1 or hasrow. Are there any other option beside SqlDataReader & SqlDataAdapter since they might take little longer. Or basically I am looking for faster way to do this.

Expand|Select|Wrap|Line Numbers
  1.         string strSQL = @"select d.department_name from departments d
  2.                         where not exists 
  3.                         (select dm.department_name, dm.emp_id from department_membership dm
  4.                         where (d.department_name=dm.department_name) and (dm.emp_id=@emp_id))
  5.                         order by d.department_name";
  6.         SqlConnection conn = new SqlConnection(connStr);
  7.         try
  8.         {
  9.         conn.Open();
  10.             SqlCommand cmd = new SqlCommand(strSQL,conn);
  11.  
OR

what if I use this query and do the count on the statement then How would I tell the program look for count >=1

Expand|Select|Wrap|Line Numbers
  1. SELECT count(holiday_description) 
  2. from HOLIDAY_SCHEDULE HS
  3. where NOT EXISTS 
  4. (select holiday_description  from HOLIDAY_DESCRIPTION hd 
  5. WHERE HS.holiday_description=hd.holiday_description)
  6.  
  7.  
Apr 23 '09 #1
3 1958
kunal pawar
297 100+
Query required more time to execute than Store procedure so prefare SP. Another thing you can right query using self join which make it more faster.
Apr 23 '09 #2
Frinavale
9,735 Expert Mod 8TB
If you don't care about the data and just need to know if a record exists I'd implement a Stored Procedure (as kunal pawar has suggested) that does a "SELECT count(x) Where Blah". Stored procedures are precompiled by the DBMS (database management system) which means your sql query doesn't have to be compiled when you execute it.
Apr 23 '09 #3
dorandoran
145 100+
Great. I have finally create Store proc to take care of this issue. Thanks guys for your input.
Apr 24 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: jester.dev | last post by:
Hello, I'm learning Python from Python Bible, and having some problems with this code below. When I run it, I get nothing. It should open the file poem.txt (which exists in the current...
17
by: keith | last post by:
I am trying to get a exact count of different distinct entries in an Access column. At first, I was trying to work with three columns, but I've narrowed it down to one to simplify it. I've searched...
2
by: Michael Howes | last post by:
I have a single DataTable in a DataSet. It has 4 columns and i'd like to get a handful of counts of unique items in 3 of the 4 columns. Can a DataTables Select or Compute methods to COUNT DISTINCT?...
8
by: Doug Bell | last post by:
Hi, I need to create a function that will return the number of columns in a passed reference to a DataView. I can find the number of columns in its underlying Data table but have not been...
7
by: Matteo Rattotti | last post by:
Hi all, i've noticed a strange beaviour of string.count: in my mind this code must work in this way: str = "a_a_a_a_" howmuch = str.count("_a_") print howmuch -> 3
23
by: Gary Wessle | last post by:
Hi I have a vector<charwhich looks like this (a d d d a d s g e d d d d d k) I need to get the biggest count of consecutive 'd'. 5 in this example I am toying with this method but not sure if...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
11
by: Mack | last post by:
Hi all, I want to write a program to count number of bits set in a number. The condition is we should not loop through each bit to find whether its set or not. Thanks in advance, -Mukesh
3
by: Dev | last post by:
Dear All, i have get combination of four PHP script for count the visitor of website but when i apply all these i have no answer. i am posting the code of all four PHP script below. CODE OF...
3
by: Hasse1982 | last post by:
Hi I have a table KDOCUMENT with the columns , , , , , ,
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.