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
 General SQL Server Forums
 New to SQL Server Programming
 How can I get a lot of 'OR' in one query

Author  Topic 

duf
Starting Member

39 Posts

Posted - 2012-07-05 : 03:25:47
Is it possible to execute a single query with many conditions OR?

SELECT SUM(WARTOSC) FROM WARTPLN WHERE FV=1 OR FV=2 ... etc

Values for a column FV i get from this query:

SELECT ID FROM FVNAG

In the latter query, there are many records and i can not connect to the first query.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-07-05 : 03:29:57
This?

SELECT SUM(WARTOSC) FROM WARTPLN WHERE FV in (SELECT ID FROM FVNAG)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

duf
Starting Member

39 Posts

Posted - 2012-07-05 : 03:39:35
Thank You
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-05 : 09:55:17
you can use exists also

SELECT SUM(WARTOSC) FROM WARTPLN w WHERE EXISTS (SELECT 1 FROM FVNAG WHERE ID = w.FV)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-07-05 : 10:36:26
well yeah. You could do those things... Or you could JOIN it.

SELECT
SUM(w.[WARTOSC]) AS [SumWar]
FROM
WARTPLN AS w
JOIN FVNAG AS ON f.[ID] = w.[FV]



Transact Charlie

Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-05 : 10:46:34
quote:
Originally posted by Transact Charlie

well yeah. You could do those things... Or you could JOIN it.

SELECT
SUM(w.[WARTOSC]) AS [SumWar]
FROM
WARTPLN AS w
JOIN FVNAG AS ON f.[ID] = w.[FV]



Transact Charlie

Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.


so long as relationship is one to one

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-07-05 : 11:18:10
Very True.

I concede the point.

Transact Charlie

Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
Go to Top of Page
   

- Advertisement -