| Author |
Topic |
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 05:14:06
|
| Can any one help in writing query to extract a date from col "bdy" bdy is a col which contains huge data ( apporx one page) which include date also say for eg as below bdy---askjldasdkfjlafj dlasjdklaskfdsjakf when monday, may 05 2008 7:30pm (GMT+5:30)askjldasdkfjlafj dlasjdklaskfdsjakf may 05 2008 7:30pm (GMT+5:30)askjldasdkfjlafj dlasjdklaskfdsjakf ladsjfasl aslkjdfasldj askjdfason 05 april 2008 this was done The above 4 records are eg. What i want is I want to extract only date part of these records and display it in the format mm/dd/yyyand store it in the temp table along with this col, or even disply it select col,bdy from item wherebdy like ' |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 05:18:19
|
| will the data be coming only any of 4 above forms? |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 05:20:01
|
| Thanks Vishak.No it can be of any form but in between may have date in any form |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 05:21:33
|
Can there be many dates in a record? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 05:27:16
|
| Yes there can be many dates |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 05:28:56
|
Are month names always spelled out or can they be abbreviated? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 05:29:56
|
| can be abbreviatedThanks,aak |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 05:31:44
|
Ok. Now it is time for you to write down ALL possible combinations of what you treat as a date.Otherwise we can play this guessing game all week long. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 05:40:17
|
| Monday,May 05 2008 (GMT +05:30)4th july 2008Thursday July 3rd,2008Thursday, july 03,20084th july 2008Tuesday, july01,2008 11:41AMFriday, July 11, 2008 9:33AM25-Oct-200710-Jan-2008may 05 2008 7:30pm (GMT+5:30)Tuesday 11/16 6:00PmMonday, Dec 20, 2:30pm ESTThe above type will be sufficientit will be run only one time to extract the dateand contains less no of record (160)Thanks for your patience Peso.aak |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 06:10:46
|
| I have rechecked it it contains only these type of dates |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 06:10:49
|
this should give you a start.;With Your_CTE (string,ID,Val) AS(SELECT t.bdy,b.ID,b.ValFROM YouRtable tCROSS APPLY dbo.ParseValues(REPLACE(t.bdy,' ',','))b)SELECT c1.bdy,CONVERT(varchar(11),CONVERT(datetime,CASE WHEN ISDATE(c1.Val)=1 AND LEN(c1.Val)>=8) THEN c1.ValWHEN ISDATE(c1.Val + ' '+c2.Val + ' '+vl.Valuelist)=1 THEN c1.Val + ' '+c2.Val + ' '+vl.ValuelistWHEN ISDATE(c1.Val + ' '+vl.Valuelist)=1 THEN c1.Val + ' '+vl.ValuelistEND),101) AS DateAloneFROM CTE c1CROSS APPLY (SELECT TOP 1 Val FROM CTE WHERE ID <c1.ID ORDER BY ID DESC)c2CROSS APPLY (SELECT TOP 2 Val + ' ' AS [text()] FROM CTE WHERE ID >c1.ID ORDER BY ID)vl(valuelist)WHERE c1.Val LIKE '%[0-9]%'AND ((ISDATE(c1.Val)=1 AND LEN(c1.Val)>=8)OR ISDATE(c1.Val + ' '+c2.Val + ' '+vl.Valuelist)=1OR ISDATE(c1.Val + ' '+vl.Valuelist)=1) the function parsevalues can be found herehttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=104485 |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 06:37:06
|
| Its giving syntax errors I have created the parsevalues function I will look into it, its taking time as I am not sqlserver backgroundcan you give the simple query just to look into the date in that column and get that date in the format mm/dd/yyyyexcluding repeatative dates etc.Thanks,aak. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 06:45:13
|
quote: Originally posted by aakcse Its giving syntax errors I have created the parsevalues function I will look into it, its taking time as I am not sqlserver backgroundcan you give the simple query just to look into the date in that column and get that date in the format mm/dd/yyyyexcluding repeatative dates etc.Thanks,aak.
select convert(varchar(11),convert(datetime,datevalue),101) |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 06:48:32
|
| thanks Visakh,I tried this select bdy, convert(varchar(11),convert(datetime,bdy),101) from mytableits is saying explicit conversion from data type ntext to datetime is not allowed |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 06:50:05
|
quote: Originally posted by aakcse thanks Visakh,I tried this select bdy, convert(varchar(11),convert(datetime,bdy),101) from mytableits is saying explicit conversion from data type ntext to datetime is not allowed
ah...so bdy is of type ntext? then parsevalues wont work. |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 06:57:59
|
| oh really then? what can be used instead of that.Thanks again for your patience Visakh.Regards,aak. |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 07:03:13
|
| I will take a backup and change the data typewhat data type you want me to have instead of ntext can I have text? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 07:24:10
|
quote: Originally posted by aakcse I will take a backup and change the data typewhat data type you want me to have instead of ntext can I have text?
nope. use varchar(max) or nvarchar(max) |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 07:30:50
|
| alter table aak alter column bdy nvarchar(max)err Incorrect synta near max.alter table aak alter column bdy nvarchar(4000)err cannot alter column bdy because it is ntexttable aak has been created but its maximum row size (35681) exceeds the max no of byte per row 8060 insert updatewill fail if the resulting row lenght exceeds 8060 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-26 : 07:32:41
|
quote: Originally posted by aakcse alter table aak alter column bdy nvarchar(max)err Incorrect synta near max.alter table aak alter column bdy nvarchar(4000)err cannot alter column bdy because it is ntexttable aak has been created but its maximum row size (35681) exceeds the max no of byte per row 8060 insert updatewill fail if the resulting row lenght exceeds 8060
are you using sql 2000? |
 |
|
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2008-09-26 : 07:54:16
|
| yes its sql server 2000 |
 |
|
|
Next Page
|