SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 WHERE clause
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rongrace
Starting Member

United Kingdom
13 Posts

Posted - 03/07/2012 :  09:29:10  Show Profile  Reply with Quote
I have a form that returns order details based on the input received in 4 parameters
using the following WHERE clause

WHERE HOrder.Acno = @Acno and
SUBSTRING(HDespatch.ArcOrdno,1,4) = @Unit and
SUBSTRING(HDespatch.ArcOrdno,5,8) >= @FromDate and
SUBSTRING(HDespatch.ArcOrdno,5,8) <= @ToDate

The current WHERE clause expects all these fields to contain data, but I want to expand the clause so that it will cater for the following.

If the Acno is blank then it will return all the orders for the unit within the date range.
If the unit is blank it will return all orders for the Acno for the date range entered.
If the date range is blank it will return all the Acno's orders for that unit

Hope this makes sense and any help would be much appreciated

webfred
Flowing Fount of Yak Knowledge

Germany
8515 Posts

Posted - 03/07/2012 :  09:40:16  Show Profile  Visit webfred's Homepage  Reply with Quote
see here:
http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/


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

rongrace
Starting Member

United Kingdom
13 Posts

Posted - 03/07/2012 :  09:43:23  Show Profile  Reply with Quote
Thanks for that, I'll have a shufty
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 03/07/2012 :  19:07:17  Show Profile  Reply with Quote
why is value stored in a concatenated format in field? why not maintain date value in its own field?

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

Go to Top of Page

rongrace
Starting Member

United Kingdom
13 Posts

Posted - 03/08/2012 :  04:50:57  Show Profile  Reply with Quote
Data came from a legacy system in that format
Go to Top of Page

DonAtWork
Flowing Fount of Yak Knowledge

2111 Posts

Posted - 03/08/2012 :  08:30:56  Show Profile  Reply with Quote
so change it to a real date. that is the best part of having a new system.

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47173 Posts

Posted - 03/08/2012 :  10:15:44  Show Profile  Reply with Quote
quote:
Originally posted by rongrace

Data came from a legacy system in that format


just keep in mind that persisting with it will really make manipulations complex. everywhere you use the individual parts you've to apply SUBSTRING functions and get them which will also have an adverse effect on performance too.

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000