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.
Author |
Topic |
sqlsquirel
Starting Member
2 Posts |
Posted - 2010-09-15 : 04:49:31
|
I have a database with this structure ID,Date, RegimenI want a query which isolates records with different regimen based on the first two characters of the regimen between date before and date next. sort the patients in order of ascending and dates in order of ascendingOutputting something like this:-ID Date Regimen1 09-Feb-10 6j1 12-Aug-10 3v1 30-Sep-10 2d7 28-Feb-05 y67 06-Dec-05 d97 05-Jan-06 6yh7 31-Mar-06 ss7 19-Feb-07 sa7 06-Jul-09 sf7 31-Aug-09 xc7 07-Dec-09 as7 26-Feb-10 xz7 26-Mar-10 tv7 30-Apr-10 xc23 03-Sep-09 bz23 04-Dec-09 mn |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2010-09-15 : 05:43:35
|
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=faqPlease see the first post in the HOW TO section. |
 |
|
kunal.mehta
Yak Posting Veteran
83 Posts |
Posted - 2010-09-15 : 08:02:28
|
select id,date,regimen order by id,date asc |
 |
|
kunal.mehta
Yak Posting Veteran
83 Posts |
Posted - 2010-09-15 : 08:02:49
|
select id,date,regimen from table1 order by id,date asc |
 |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2010-09-15 : 09:43:23
|
Hence my reason for the post on how to ask a question, the data set looks like the end result the OP wants, but doesn't give a starting position. |
 |
|
sqlsquirel
Starting Member
2 Posts |
Posted - 2010-09-16 : 04:59:27
|
looks like no body understood what i mean't. i need the query to display only when there is a differece in regimen between the date before and date after i.e if the first date is 09-Feb-2010 and the next date is 12-Aug-2010 and then the regimens are different between those two dates then the query should display |
 |
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2010-09-16 : 06:29:27
|
i vaguely understand what you want. Can you provide sample data as well. Your first post just has the output. |
 |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2010-09-16 : 07:39:37
|
sqlsquirel - See post dated 09/15/2010 : 05:43:35 |
 |
|
|
|
|