473,407 Members | 2,676 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,407 software developers and data experts.

Urgent deliverable

Hi

I have a query as follows

select * from
( select CompanyID , TickerSymbol , CompanyName,
dbo.FormatNumber(LatestClosingPrice,2) as 'CurrentPrice' from
backscreeningdata3
where dailydate= '12/31/04' and (LatestClosingPrice>100) ) as m0,
( select CompanyID , TickerSymbol , CompanyName,
dbo.FormatNumber(LatestClosingPrice,2) as 'CurrentPrice' from
backscreeningdata3 where dailydate= '12/31/04' and
(LatestClosingPrice>150) ) as m1
where 1=1 and m0.CompanyId=m1.CompanyId
Order By m0.Tickersymbol asc

And the resultset is follows

ALX ALEXANDER'S INC 215 215
BRK.A BERKSHIRE HATHAWAY -CL A 87900 87900
CME CHICAGO MERC EXCH HLDGS 228.7 228.7
FFH FAIRFAX FINANCIAL HLDG 168.5 168.5
GOOG GOOGLE INC 192.79 192.79
GREY GREY GLOBAL GROUP INC 1099.99 1099.99
MKL MARKEL CORP 364 364
NVR NVR INC 769.4 769.4
NWLIA NATIONAL WESTERN LIFE 166.5 166.5
SEB SEABOARD CORP 998 998
STU STUDENT LOAN CORP 184 184
WPO WASHINGTON POST -CL B 983.02 983.02
WSC WESCO FINANCIAL CORP 393 393
Y ALLEGHANY CORP 285.25 285.25

ie i get the common stocks that exits in both the criteria

but my requirement is i want all the stocks that pass each criteria
Jul 23 '05 #1
2 1222

Try to use outer joins. See more on BOL

Madhivanan

Jul 23 '05 #2
On 2 Mar 2005 23:20:07 -0800, Kalyan wrote:
I have a query as follows (snip)but my requirement is i want all the stocks that pass each criteria


Hi Kalyan,

I fail to see how your query can produce the posted results. As a result
of SELECT * and the two joined derived tables, you should have a result
set of 8 columns: CompanyID, TickerSymbol, CompanyName, CurrentPrice,
CompanyID, TickerSymbol, CompanyName, CurrentPrice. And the last four
columns should be equal to the first four on each row.

I also don't understand your requirements. The first derived table
selects rows based on dailydate 12/31/04 and LatestClosingPrice > 100;
the second derived table selects the same dailydate and increases the
threshold for LatestClosingPrice to 150. If you want stocks that pass
both criteria, you can simply run the second derived table only, as
having a LatestClosingPrice > 150 ensures that it will also be > 100.

SELECT CompanyID, TickerSymbol, CompanyName,
dbo.FormatNumber(LatestClosingPrice,2) AS CurrentPrice
FROM backscreeningdata3
WHERE dailydate= '20041231' -- Changed to unambiguous YYYYMMDD format
AND LatestClosingPrice > 150

And if you want stocks that pass one or both of the criteria, run the
first derived table as a standalone query:

SELECT CompanyID, TickerSymbol, CompanyName,
dbo.FormatNumber(LatestClosingPrice,2) AS CurrentPrice
FROM backscreeningdata3
WHERE dailydate= '20041231' -- Changed to unambiguous YYYYMMDD format
AND LatestClosingPrice > 100

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kalyan | last post by:
hello everybody, I'am new to SQLServer.I have records from table as follows. column1 column2 column3 column4 column5 -------- ------------------- ------- ...
5
by: Kalyan | last post by:
I had got a table with 3 columns. I had to get the sum of the third column divide it by 10. let it be named as total. then finally i had to split my records into 10 groups such that the sum of...
28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
7
by: kalikoi | last post by:
I have two arrays as follows array1=("45101010","45101010","45103020","45103020","45103020","45201020","45201020", "45201020","45201020","45202010") ...
4
by: ramaswamynanda | last post by:
Hello, I have an application in Access where I have developed about 10 reports. These have been working for a while and produce data properly. I recently tried exporting the report, from the...
7
by: Cirene | last post by:
I used to use the Web Deployment Project with my VS2005 projects. Now I've fully upgraded to VS2008. Do I have to download a new version of the Web Deployment Project? If so where can I find...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.