473,652 Members | 3,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determine which fields to select based on date

5 New Member
Hi, I'm developing a service provider listing service. Part of the specification is to have both an address and a 'seasonal address' for each listing. The database stores the start and end months during which the seasonal address should be displayed as the address. Right now I am just grabbing everything out of the database, and using ASP to determine which address to display (seasonal if it is within the month range, normal otherwise [this works fine]).

However, now the client wants me to change how the records are sorted. They want everything to sort by State, then City, then Company Name. The problem is that I have two fields for State (seasonal and normal), and same for City, so I can't figure out how to sort them correctly. Each record has its own value for when the seasonal address should start and end.

I've been experimenting with the following SQL statement, but it doesn't work right:
Expand|Select|Wrap|Line Numbers
  1. SELECT C.* FROM ServiceMap.tblCaptains C, ServiceMap.tblCaptRegionLink R WHERE C.Status = '1' AND C.ListingStart <= '8/8/2008' AND C.ListingEnd >= '8/8/2008' AND R.Region = 'SE' AND R.Capt_ID = C.ID ORDER BY R.InRegn DESC,
  2. CASE WHEN S_From <> '' AND S_From < S_To AND (DATEPART(m,getDate()) >= S_From AND DATEPART(m,getDate()) <= S_To) THEN S_State
  3. WHEN S_From <> '' AND S_From < S_To AND (DATEPART(m,getDate()) < S_From OR DATEPART(m,getDate()) > S_To) THEN State
  4. WHEN S_From <> '' AND S_From > S_To AND (DATEPART(m,getDate()) <= S_From AND DATEPART(m,getDate()) >= S_To) THEN State
  5. WHEN S_From <> '' AND S_From > S_To AND (DATEPART(m,getDate()) > S_From OR DATEPART(m,getDate()) < S_To) THEN S_State 
  6. WHEN S_From = '' THEN State
  7. END
  8. ASC, C.Company ASC, C.FName ASC
Does anyone have any ideas?
Thanks,
Andrew
Aug 8 '08 #1
2 1591
Delerna
1,134 Recognized Expert Top Contributor
I suggest you take the address display decision away from asp and move it to the query.
What I mean is like this
sorry to be cryptic but I can't determine enough from your post to show my meaning clearer
I am assuming you are comparing the seasonal month range with the month of the current date.
Expand|Select|Wrap|Line Numbers
  1. select YourOtherFields,
  2.           case when datepart(m,getdate())>=r.startmonth 
  3.                     and datepart(m,getdate())<=r.endmonth
  4.           then r.address else c.address end as address,
  5.  
  6.           case when datepart(m,getdate())>=r.startmonth 
  7.                     and datepart(m,getdate())<=r.endmonth
  8.           then r.state else c.state end as state
  9.  
  10. from tblCaptains c
  11. join tblCaptRegionLink r on YourJoinConditions
  12.  
Now that you only have 1 address field and 1 state field.
sorting should be much easier.
Aug 8 '08 #2
Delerna
1,134 Recognized Expert Top Contributor
Actually, reading your post again you are using S_From and S_To for the month comparison, so use them!

Expand|Select|Wrap|Line Numbers
  1. select YourOtherFields,
  2.           case when datepart(m,getdate())>=S_From 
  3.                     and datepart(m,getdate())<=S_To
  4.           then S_Address else Address end as address,
  5.  
  6.           case when datepart(m,getdate())>=S_From
  7.                     and datepart(m,getdate())<=S_To
  8.           then S_State else state end as State
  9.  
  10. from tblCaptains c
  11. join tblCaptRegionLink r on YourJoinConditions
  12.  
Aug 8 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
17218
by: Bill | last post by:
Hello out there; This may be a challenge but I'm certain it's possible but I can't seem to figure out how. I have a table that has several date fields, e.g., Date1, Date2, Date3, Date4 ... etc. I wish to find out either of two things for each row. 1) What is the maximun date in any of the date fields in the row.
3
6609
by: Melissa | last post by:
I have this table: TblProjectYear ProjectYearID ProjectYearStartDate ProjectYearEndDate The Project Year will always span across December 31; for example 9/1/04 to 6/30/05. How do I build a combobox based on this table that will display all the months between the StartDate and the EndDate for a given ProjectYearID and when a selection is made, the full date of the last day of the selected
8
3712
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: "Date","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11","P12","P13","P14","P15","P16","P17","P18","P19","P20","P21" 1/1/2005,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21 1/2/2005,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
40
2961
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the front end open at the first form) and even though this links to the back-end files, there are no ldb files created. This is so I know when it is safe to compact the back-end files without going round to make sure everyone is logged off. User...
6
14344
by: Jana | last post by:
Greetings Access Gurus! I am working on an app to send batch transactions to our bank, and the bank requires that we place an effective date on our files that is 'one business day in the future, excluding holidays and weekends.' I didn't want to build a table of holidays that would have to be continuously updated, so I searched high and low for a function that would tell me whether a given date was a holiday, to no avail. I did find an...
2
4180
by: jennwilson | last post by:
I am trying to generate a report based on a query that will list any records where an individual has a date listed that matches the specified time for one or both of the date fields. The two fields are danpdate and testdate. SELECT PatientDemo.PatientType, PatientDemo.ClinicianName, PatientDemo.ClientName, PatientDemo.DOB, PatientDemo.FacilityName, PatientDemo.PrimaryInsurance, PatientDemo.SecondaryInsurance,...
7
2092
by: creative1 | last post by:
Hello everyone. I am experiencing a strange problem that I can't fix on my own. I think I need expert's suggestions for this. The problem is: I want to print account statement (or any other report) from VB form based on an entered date in the masked fields (dd/mm/yy). I am using one form to display five reports. I send date to display report after formatting it (m/dd/yy). When I enter date range like this in masked textbox (DD/MM/YY) ...
3
2377
Jerry911
by: Jerry911 | last post by:
I have a form that uses a pick list to select a specified date/time range based on the case value. Case 1-7 have pre-defined date/time functions, but case 8 is for a custom date/time range. I only want to show the custom fields when the custom date range option is selected. When the form loads I have all the fields hidden. Private Sub Form_Load() Me!CustomDateBox.Visible = False Me!dtpStartDate.Value = Date Me!dtpEndDate.Value = Date...
482
27568
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. what i am trying to display previously entered multiple fields. I am able to get my serial fields to display correctly, but i can not display my parts fields correctly. Currently this is what it does serial information 1 parts 1
0
8279
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8703
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8589
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.