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 2008 Forums
 Transact-SQL (2008)
 Inserting null values in numeric

Author  Topic 

shinelawrence
Starting Member

32 Posts

Posted - 2013-03-11 : 08:01:24
Hi Everyone,
I insert numeric values in DB. If it empty textbox then the query is simple,,..so i got error. How to do. Please tell the solution.

Thanks In Advanced

Lawce

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2013-03-11 : 12:01:04
The code example below works , using the NULL into a numeric data type. The ideal situation is to check and handle this type of situation at the application level ,

create table #temp1
(myname nvarchar(100),
age NUMERIC)


INSERT INTO #temp1
select 'Kevin' , null

select * from #temp1

drop table #temp1



Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-11 : 12:34:00
you need to determine as per your rules whether you want to populate NULL or 0 as value in those cases

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

shinelawrence
Starting Member

32 Posts

Posted - 2013-03-12 : 00:30:26
thank you for ur kinldy reply.. If my texbox have empty value then it should be stored at backend as 0 or if my textbox has value then it should be store...

my querey is:
insert into tbl_name values(1500.25)

if it's empty how to store 0... Please tell the solution...

Thanks In Advanced

Lawce
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-12 : 00:37:50
quote:
Originally posted by shinelawrence

thank you for ur kinldy reply.. If my texbox have empty value then it should be stored at backend as 0 or if my textbox has value then it should be store...

my querey is:
insert into tbl_name values(1500.25)

if it's empty how to store 0... Please tell the solution...

Thanks In Advanced

Lawce


check for blanks and make it as 0
ie do something like

CASE WHEN @TextboxValue > '' THEN @TextboxValue ELSE 0 END

@TextboxValue is parameter through which you pass the textbox entered value to database

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

shinelawrence
Starting Member

32 Posts

Posted - 2013-03-12 : 00:50:32
ok...thank you... so i need to write stored procedure...

Lawce
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-12 : 00:52:48
yep...its recommended. you can even handle it in adhoc sql though

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -