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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Getting different between variable between dates

Author  Topic 

sqlsquirel
Starting Member

2 Posts

Posted - 2010-09-15 : 04:49:31
I have a database with this structure ID,Date, Regimen
I 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 ascending
Outputting something like this:-
ID Date Regimen
1 09-Feb-10 6j
1 12-Aug-10 3v
1 30-Sep-10 2d
7 28-Feb-05 y6
7 06-Dec-05 d9
7 05-Jan-06 6yh
7 31-Mar-06 ss
7 19-Feb-07 sa
7 06-Jul-09 sf
7 31-Aug-09 xc
7 07-Dec-09 as
7 26-Feb-10 xz
7 26-Mar-10 tv
7 30-Apr-10 xc
23 03-Sep-09 bz
23 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=faq

Please see the first post in the HOW TO section.
Go to Top of Page

kunal.mehta
Yak Posting Veteran

83 Posts

Posted - 2010-09-15 : 08:02:28
select id,date,regimen order by id,date asc
Go to Top of Page

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
Go to Top of Page

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.
Go to Top of Page

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
Go to Top of Page

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.
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -