April 9, 2014 at 10:59 am
Hi All,
Create Table Test01(
business_date date)
1. Insert into test01 (business_date) values ('2013may6')
2. Insert into test01 (business_date) values ('20140409')
In the above example both the statement will succeed. But as per our requirement, the first statement should fail on inserting (i.e) if a date value is on text then it should file. Since the insertion is happening from a third party tool, the settings should be set on the table. Please help.
---------------------------------------------------
Thanks,
Satheesh.
April 9, 2014 at 11:08 am
i wouldn't do this; the date format is valid, and since it goes into a date typed field, how does that adversely affect you?
what if an application passed a date or datetime field as a parameter? an implicit conversion from datetime to date would occur, which does not have a string pattern at all?
i don't think you can even capture this in a table trigger, because it would already be cast to the datatype of date in the INSERTED/DELETED tables by the time it hit the trigger.
Lowell
April 9, 2014 at 11:11 am
Satheesh E.P. (4/9/2014)
Hi All,Create Table Test01(
business_date date)
1. Insert into test01 (business_date) values ('2013may6')
2. Insert into test01 (business_date) values ('20140409')
In the above example both the statement will succeed. But as per our requirement, the first statement should fail on inserting (i.e) if a date value is on text then it should file. Since the insertion is happening from a third party tool, the settings should be set on the table. Please help.
I am unfortunately unaware of any way to prevent implicit data conversions where such conversion is successful. Realize that both of your inserts above rely on implicit data conversions to work.
April 9, 2014 at 12:05 pm
The best way to prevent implicit conversions is to explicitly convert them or design the tables and code to match in datatype and size.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 9, 2014 at 12:06 pm
Only way to do this is to implement a trigger, I recommend an INSTEAD OF trigger and do your validation in the trigger.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
April 9, 2014 at 4:59 pm
All good suggestions. My favorite, though, is to put the hammer on the 3rd party providing the data and get them to clean up their act.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 9, 2014 at 8:51 pm
Jeff Moden (4/9/2014)
All good suggestions. My favorite, though, is to put the hammer on the 3rd party providing the data and get them to clean up their act.
I've never seen a hammer big enough to get any 3rd party to provide proper data 😀 "It loads into Excel and that's the standard!" I'm really jealous.
April 10, 2014 at 2:51 am
Satheesh E.P. (4/9/2014)
Hi All,Create Table Test01(
business_date date)
I have to agree with Lowell, that if the column datatype is a date, then the insert will succeed and be correct and should not cause you a problem.
If, however, the column data type is not really "date", but is, in fact, string based, then you could use a check constraint or a calendar table / foreign key to enforce good data.
Probably the best thing - if you can - is to make the third party use a stored procedure though, not insert directly into your tables.
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply