473,513 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stored procedure with if condition on column names

94 New Member
Dear Friends,
Would any body knew the solution for this?
If Gross Weight value is null i would get Divide by Zero error. So
I have to check whether Grossweight is zero or not, to get the result.I cant check this in aspx.cs file becoz each InternalControl No has different Grosswt.and I do not know the gross weight while i call this sp. Please help what to do?
Expand|Select|Wrap|Line Numbers
  1. Create procedure [dbo].[USP_ImportPaymentView_Select]                                    
  2. @Internalcontrolnumber nvarchar(100),                
  3. @FromDate varchar(20),                                  
  4. @ToDate varchar(20)
  5. As
  6. Select 
  7. Gross Weight,
  8. TLCActualGrossValue=round((TotalFreightValue/GrossWeight),2),
  9. from importpaymentview                            
  10. where      
  11. (Yearofimport between @FromDate and @ToDate)                                 
  12.   or (InternalControlNumber =@Internalcontrolnumber)    
May 11 '07 #1
3 8211
frozenmist
179 Recognized Expert New Member
Hi ,
try giving case statment in the SELECT
Like
Select ...
CASE WHEN grossweight is null then else

Also if you want to assign a default value to gross weight when it is null then you can give
ISNULL(grossweight,default value)

Hope these hints are useful
Cheers
May 11 '07 #2
frozenmist
179 Recognized Expert New Member
Hi,
If you want to use the case try this piece of code
Expand|Select|Wrap|Line Numbers
  1. Select 
  2. Gross Weight,
  3. CASE when GrossWeight is not  NULL 
  4.           then   round((TotalFreightValue/GrossWeight),2)
  5.           else NULL End as TLCActualGrossValue
  6. from importpaymentview                            
  7. where      
  8. (Yearofimport between @FromDate and @ToDate)                                 
  9.   or (InternalControlNumber =@Internalcontrolnumber)    
  10.  

Hope it works,because i couldnt run and see it.
Cheers
May 11 '07 #3
sudhaMurugesan
94 New Member
Thanks Mr.FrozenMist.
I had already used a default value for gross weight. I try with select case too. Thanks for your idea.
May 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2837
by: Toonman | last post by:
I'm trying to use a couple of variables in a stored procedure. Things work fine when I hard code the data into the variables and also work fine when I use the variable in the WHERE clause and hard...
3
2531
by: Gary Besta | last post by:
I am trying to add a simple case statement to a stored procedure or user defined function. However when I try and save the function/procedure I get 2 syntax errors. Running the query in query...
5
5139
by: Raquel | last post by:
This is a very simple DB2 SQLJ stored procedure. The problem is that it seems to run fine but returns NOTHING. I mean..as if nothing has happened..not resultset is returned. I am passing value...
1
2555
by: Raquel | last post by:
Have a question on the Stored procedure method code generated by DB2 development center for Java stored procedures. Suppose I have a requirement to return the resultset consisting of FIRSTNME,...
8
7895
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
0
2630
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
2
4465
by: Joe Campbell | last post by:
I have a DBA that wrote a stored procedure that does a SELECT from a particluar SQL Server table. Within that stored procedure he links over to grab a column from another database table. I need to...
0
926
by: Jeff Harkavy | last post by:
Is this possible or am I barking up the wrong hydrant? I want to have a FormView (ASP.NET 2.0, obviously) on a web page that's populated via a stored procedure. There are two sections of the...
2
1240
by: Fir5tSight | last post by:
Hi, I have a stored procedure that looks like the follows: ------------------------------------------------------------------------------------- SELECT ClientName AS 'Client Name', Location,...
0
1737
by: =?Utf-8?B?X3ByZWZpeA==?= | last post by:
Hello All, I have written a page with a sqlserverdatasource control and a formview web control. I want to use stored procedures to perform CRUD operations. Formview textboxes bind to table...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.