Is there a way to check the type of a value before inserting the value into the table? I am working with sql 7 and I need to verify the input values to a table before inserting them.
For example...
table A, field1 is an integer field type
default value=0;
value//input value from application
if value (future value) is an integer to be inserted into field1 then
insert(value)
else
insert(default value)
This is just a simple logic procedure I want the trigger to check before inserting or updating field1
You could use isnumeric, e.g.
DECLARE @.def INT
SET @.def = 0
INSERT tbl(col) SELECT CASE WHEN ISNUMERIC(@.param)=1 THEN @.param ELSE @.def
END
Though mind that IsPerfect(IsNumeric())=0.
http://www.aspfaq.com/2390
http://www.aspfaq.com/
(Reverse address to reply.)
"Carlos Aguero" <carlos986@.hotmail.com> wrote in message
news:C1FDEFB3-88D3-4EA7-8A24-3B663EEF71EE@.microsoft.com...
> Is there a way to check the type of a value before inserting the value
into the table? I am working with sql 7 and I need to verify the input
values to a table before inserting them.
> For example...
> table A, field1 is an integer field type
> default value=0;
> value//input value from application
> if value (future value) is an integer to be inserted into field1 then
> insert(value)
> else
> insert(default value)
> This is just a simple logic procedure I want the trigger to check before
inserting or updating field1
|||You could use the CASE statement in an insert statement:
create table #test(c char(1), i int)
declare @.x varchar(10)
set @.x = 1
insert into #test values('a', case when isnumeric(@.x) = 1 then @.x else 0
end)
set @.x = 'xxx'
insert into #test values('a', case when isnumeric(@.x) = 1 then @.x else 0
end)
select * from #test
drop table #test
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Carlos Aguero" <carlos986@.hotmail.com> wrote in message
news:C1FDEFB3-88D3-4EA7-8A24-3B663EEF71EE@.microsoft.com...
> Is there a way to check the type of a value before inserting the value
into the table? I am working with sql 7 and I need to verify the input
values to a table before inserting them.
> For example...
> table A, field1 is an integer field type
> default value=0;
> value//input value from application
> if value (future value) is an integer to be inserted into field1 then
> insert(value)
> else
> insert(default value)
> This is just a simple logic procedure I want the trigger to check before
inserting or updating field1
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment