April 14, 2010 at 6:19 am
Hi,
try this:
drop the constraint first
ALTER TABLE [dbo].[Table_1] DROP CONSTRAINT [DF_Table_1_T1]
then convert and add teh constraint again
April 14, 2010 at 6:56 am
Hi Luzi, thanks for your replies, i tried what u said, but i think the problem is comming from the table, because i checked the field for invalid data and got some. after this i tried to convert again after dropping the constraint, it complained it cant convert string to datetime, is there any way i can get out the record that does not conform to the format, so i can know where the error lies?
Thanks
Timotech
April 14, 2010 at 7:27 am
timotech (4/14/2010)
Hi Luzi, thanks for your replies, i tried what u said, but i think the problem is comming from the table, because i checked the field for invalid data and got some. after this i tried to convert again after dropping the constraint, it complained it cant convert string to datetime, is there any way i can get out the record that does not conform to the format, so i can know where the error lies?Thanks
Timotech
Hi,
what is your Field now look like?
to find chars you can try serach with
where Field not like '[0-9]%' (for rows without digit at the begin)
or Field is null (for empty rows)
take a look at the field and get a proper pattern to search for. e.g (not like '[0-9][0-9]:%`) for 2 digits and a ':'
April 14, 2010 at 7:43 am
Hi Luzi, Thanks so much for your help, it has finally worked, i had to go through the records one at a time, then later discovered that some time entries were entered in the following format 00:00;00, then i had to run a query such as :
select lower_time from tbl_tvrates where lower_time like '%;%' so it brought be the culprits, i edited them and ran my former query again and everything worked exactly as i wanted it.
I'm very greatful thank u so much and the other guys that contributed.
God bless u all.
Thanks
Timotech.
You can reach me on timotech@yahoo.com
April 14, 2010 at 8:21 am
your welcome,
maybe in this case your next step is to create a check constraint?
like
ALTER TABLE [dbo].[Table_1] WITH NOCHECK ADD CONSTRAINT [CK_Table_1_T1_2] CHECK NOT FOR REPLICATION (([T1] like '[0-9][0-9]:[0-9][0-9]:[0-9][0-9]'))
ALTER TABLE [dbo].[Table_1] CHECK CONSTRAINT [CK_Table_1_T1_2]
April 14, 2010 at 8:58 am
Hi Luzi, why do i still need to do a constraint, since i have what i need?
April 14, 2010 at 10:04 am
Did you get the column converted to a datetime data type? If so, that constraint won't help you.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
April 14, 2010 at 10:11 am
Thanks wayne, i'll stick to your advice. Thanks so much for your help.
Timotech
April 17, 2010 at 7:36 am
Hi thanks Stewart, some nice tsql there, you guys are gurus.
Viewing 9 posts - 16 through 24 (of 24 total)
You must be logged in to reply to this topic. Login to reply