Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 atleast

Author  Topic 

kandy
Starting Member

15 Posts

Posted - 2006-10-04 : 15:22:00
what is the equivalent for "atleast" in sql.
atleast one customer with balance>...

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-10-04 : 15:37:15
Do you mean greater than sign, >?

Tara Kizer
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2006-10-04 : 16:31:36
Candy, come over to my place and we can go through these things together...

rockmoose
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-04 : 20:57:43
quote:
Originally posted by rockmoose

Candy, come over to my place and we can go through these things together...

rockmoose




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-10-05 : 01:40:25
quote:
Originally posted by kandy

what is the equivalent for "atleast" in sql.
atleast one customer with balance>...



Its depends on the condition what you are giving.. for instance you can use Exists statement for that..

somthing like this


If (Select Count(1) From TableName) >=1 Then
--Do somthing


Please post the questions with more details, if you want a perfect result.

Chirag
Go to Top of Page

kandy
Starting Member

15 Posts

Posted - 2006-10-05 : 14:04:24
this is what i need..

a nested query to find the number, last name, and first name of each sales representative who represents at least one customer with a credit limit equal to $5,000.

i have a rep table with rep_num,last_name and first_name and customer table with credit_limit and rep_num.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-10-05 : 14:25:29
Don't quite see why you see this as an "at least" issue?

Don't you just need to SELECT from the CUSTOMER table WHERE credit_limit = 5000, and also JOIN the representative table ON representative.rep_num = customer.rep_num ?

Or have I misunderstood the question?

EDIT: Yeah, well I misread it at least! the EXISTS solution below is more appropriate.

Kristen
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-05 : 15:19:27
[code]SELECT number, [last name], [first name]
FROM [sales representative]
WHERE EXISTS (SELECT *
FROM customer
WHERE creditlimit = 5000 AND customer.repNumber = [sales representative].number)[/code]
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-10-06 : 00:31:00
snSQL I reckon that's less efficient than starting with the CUSTOMER table and joining the Representative (but it is a valid route - which may have been all you were demonstrating!)

Kristen
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-06 : 01:05:35
quote:
I reckon that's less efficient than starting with the CUSTOMER table and joining the Representative

I don't think so - if there are lots of customers per rep then you are going to get all the customers unecessarily. All kandy wants to know is whether there is at least one such customer, and if so return the rep for that customer. She doesn't actually want the customers, she wants the reps.
quote:
query to find the number, last name, and first name of each sales representative who represents at least one customer with a credit limit equal to $5,000
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-10-06 : 01:14:25
"She doesn't actually want the customers, she wants the reps."

My apologies, I misread the question as the first/last name of the customer.

Kristen
Go to Top of Page

kandy
Starting Member

15 Posts

Posted - 2006-10-06 : 15:17:19
thank u !!!yeah i wanted the rep number.query worked.i dont have duplicates now.
Go to Top of Page
   

- Advertisement -