473,385 Members | 1,587 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,385 software developers and data experts.

Hand needed with t-sql

Is it possible to write these two blocks of code as one? The only
difference between them is the AND clause: AND is_trade_date = 1 versus AND
is_sett_date = 1.

Cheers,

David

IF (@trade_dates = 1)
BEGIN
IF EXISTS (SELECT 1 FROM calendar
WHERE calendar_date = @date
AND is_trade_date = 1)
BEGIN
SELECT @day_cnt = @day_cnt + 1
END
END
ELSE
BEGIN
IF EXISTS (SELECT 1 FROM calendar
WHERE calendar_date = @date
AND is_sett_date = 1)
BEGIN
SELECT @day_cnt = @day_cnt + 1
END
END
END
Jul 20 '05 #1
3 2863
David (au*******@hushmail.com) writes:
Is it possible to write these two blocks of code as one? The only
difference between them is the AND clause: AND is_trade_date = 1 versus
AND is_sett_date = 1.


If my guess of the logic is right:

IF EXISTS (SELECT 1
FROM calendar
WHERE calendar_date = @date
AND (is_trade_date = 1 OR @trade_dates = 0)
AND (is_sett_date = 1 OR @trade_dates = 1)
BEGIN
SELECT @day_cnt = @day_cnt + 1
END

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
Why not:
IF (@trade_dates = 1)
BEGIN
IF EXISTS (SELECT 1 FROM calendar
WHERE calendar_date = @date AND
(is_trade_date = 1 OR is_sett_date = 1)
)
BEGIN
SELECT @day_cnt = @day_cnt + 1
END
END

Ricardo

"David" <au*******@hushmail.com> wrote in message news:<3f***********************@news.optusnet.com. au>...
Is it possible to write these two blocks of code as one? The only
difference between them is the AND clause: AND is_trade_date = 1 versus AND
is_sett_date = 1.

Cheers,

David

IF (@trade_dates = 1)
BEGIN
IF EXISTS (SELECT 1 FROM calendar
WHERE calendar_date = @date
AND is_trade_date = 1)
BEGIN
SELECT @day_cnt = @day_cnt + 1
END
END
ELSE
BEGIN
IF EXISTS (SELECT 1 FROM calendar
WHERE calendar_date = @date
AND is_sett_date = 1)
BEGIN
SELECT @day_cnt = @day_cnt + 1
END
END
END

Jul 20 '05 #3
The following block should do the trick:
IF EXISTS ( SELECT 1
FROM calendar
WHERE calendar_date = @date AND
(
( is_trade_date = 1 AND
@trade_dates = 1
)
OR
( is_sett_date = 1 AND
@trade_dates <> 1
)
)
)
BEGIN
SELECT @day_cnt = @day_cnt + 1
END

although not very elegant...

Ricardo.
"David" <au*******@hushmail.com> wrote in message news:<3f***********************@news.optusnet.com. au>...
Is it possible to write these two blocks of code as one? The only
difference between them is the AND clause: AND is_trade_date = 1 versus AND
is_sett_date = 1.

Cheers,

David

IF (@trade_dates = 1)
BEGIN
IF EXISTS (SELECT 1 FROM calendar
WHERE calendar_date = @date
AND is_trade_date = 1)
BEGIN
SELECT @day_cnt = @day_cnt + 1
END
END
ELSE
BEGIN
IF EXISTS (SELECT 1 FROM calendar
WHERE calendar_date = @date
AND is_sett_date = 1)
BEGIN
SELECT @day_cnt = @day_cnt + 1
END
END
END

Jul 20 '05 #4

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

Similar topics

21
by: Tony Marston | last post by:
If the use of the browser's BACK button is interfering with the operation of your web application then take a look at this article entitle "Back Button Blues" ...
102
by: RFox | last post by:
I date back to the early days of the web when HTML was limited but very managable, and have always maintained that hand-coding HTML gives you far better control and cleaner HTML markup than any...
4
by: jake | last post by:
Maybe some kind person can help with a suggestion or two ;-) I want to construct a banner on a number of pages in the format: LHS: Text (variable content) RHS. Logo ..... each with a...
6
by: WindAndWaves | last post by:
Hi Folks I would like to improve the look and feel of my buttons as I do not like the grey buttons that come with access. Important to me are: a. that it is clear to the user that the buttons...
4
by: tijgetje | last post by:
Hello newsgroup, I want to create a C# program in which the user is able to draw free-handed (eg. Paint) on top of a picture. The program is for use on pocket pc (edition windows mobile 2005)....
17
by: M.Siler | last post by:
I'm trying to get my head around a conversation I had with a developer the other day. We were talking about Codesmith vs. Hand coding. He's position is Codesmith is for junior to mid level...
1
by: Martin Olsen | last post by:
Hi all. I am creating a program which calculates poker odds. The program should look at the visible cards (those on your hand and those on the table) then count the cards needed to improve the...
2
by: DesiShaddy | last post by:
Hi Guys, I have all my code working except sort function . I need to sort the cards in hand......and I am having hard time with that.... Any help would be really helpful ;) class hand{...
10
by: ikarus | last post by:
Hello C++ Gurus! I'm comparing sorting algorithm for study goals. I've compared STL std::sort and hand-coded introsort on millions (tens of millions) of integers array sorting. It was tested...
3
by: MyWaterloo | last post by:
I need some help with an inventory type question. To lay the foundation... I have an inventory database that keeps track of parts for rebuilds. The tables are: CATEGORIES which is linked to table...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.