Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 21st, 2005, 12:46 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
IF ...Else

Can you use IF Stmt to check for a particular value?

For instance:

IF (select lm.BCID = 2)
From lm INNER JOIN lc
ON lm.lid = lc.lid
WHERE lc.ecid = 66
BEGIN
SELECT stmts.....
END

ELSE

IF (select lm.BCID = 7)
FROM lm INNER JOIN lc
ON lm.lid = lc.lid
WHERE lc.ecid = 67
BEGIN
SELECT stmts.....
END

I'm receiving error messages in my syntax but I'm not why. I thought maybe because I am not passing a boolean expression.

Reply With Quote
  #2  
Old January 21st, 2005, 01:05 PM
samcneal samcneal is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 75 samcneal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 26 m 2 sec
Reputation Power: 4
I've modified the code to this:

IF (select lm.BCID From lm INNER JOIN lc
ON lm.lid = lc.lid
WHERE lc.ecid = 66) = 2
BEGIN
SELECT stmts.....
END

ELSE

IF (select lm.BCID
FROM lm INNER JOIN lc
ON lm.lid = lc.lid
WHERE lc.ecid = 67) = 7
BEGIN
SELECT stmts.....
END

And my syntax is ok but now the errors I get are the following:

Server: Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Server: Msg 512, Level 16, State 1, Line 76
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

I kinda why but I'm not sure of how to fix it. Any ideas?

Reply With Quote
  #3  
Old January 24th, 2005, 06:26 PM
Lauramc's Avatar
Lauramc Lauramc is offline
SQL Slarentice
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: In My Happy Place
Posts: 1,785 Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level)Lauramc User rank is General 2nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 16 h 14 m 43 sec
Reputation Power: 1096
In your IF statements you are nesting a query. You can only use this type of statement if it returns only one result. I assume that the nested query has many rows that meet that criteria.

You could do several things. You can use SELECT...INTO for your nested query, selecting the results into a separate table. This table would contain only the matching results. If you rebuild the table each time your query runs, you can then use the second table to perform whatever action you wish.

Reply With Quote
  #4  
Old January 28th, 2005, 05:16 AM
Tonny-Soeroso Tonny-Soeroso is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 36 Tonny-Soeroso User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 56 m 27 sec
Reputation Power: 0
Thumbs up

try your query :

select lm.BCID From lm INNER JOIN lc
ON lm.lid = lc.lid
WHERE lc.ecid = 66


i guess that query return more than 1 row..
if u use any expression, it only work if there is only 1 row for comparisson.



Regards,

Tonny Soeroso

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > IF ...Else


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT