SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Inserting null values in numeric
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shinelawrence
Starting Member

India
32 Posts

Posted - 03/11/2013 :  08:01:24  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
2067 Posts

Posted - 03/11/2013 :  12:01:04  Show Profile  Visit jackv's Homepage  Reply with Quote
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

India
52317 Posts

Posted - 03/11/2013 :  12:34:00  Show Profile  Reply with Quote
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

India
32 Posts

Posted - 03/12/2013 :  00:30:26  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 03/12/2013 :  00:37:50  Show Profile  Reply with Quote
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

India
32 Posts

Posted - 03/12/2013 :  00:50:32  Show Profile  Reply with Quote
ok...thank you... so i need to write stored procedure...

Lawce
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 03/12/2013 :  00:52:48  Show Profile  Reply with Quote
yep...its recommended. you can even handle it in adhoc sql though

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000