Can't Get This SQL Figured Out

Jun 10, 2008

Hi all,
 I am trying to get batting average, which you get by dividing # hits / # at bats.  However, I have to protect against divide-by-zero error.  Therefore, I came up with the following:
SELECT  P.hits/(IsNull(NullIF(P.atbats, 0), 1)) AS Average FROM Players P
 
However, this gives me 0 for ALL cases for some reason.  Even when hits = 13 and AB = 16.
Can someone please help and let me know what is wrong with my query?  I cannot figure it out! :(
Thanks in advance!!!! 

View 3 Replies


ADVERTISEMENT

Okay, I Thought I Had The Return Value From A Statement Figured Out...

Nov 15, 2007

  So, Jimmy G helped me out with it in showing a little bit how to do it. SqlCommand command = new SqlCommand(, object>)
SqlParameter param = new SqlParameter();
param.ParameterName = "@return";
param.Direction = ParameterDirection.ReturnValue;
command.Parameters.Add(param);

command.ExecuteNonQuery();

//get the return value
int val = int.Parse(command.Parameters[0].ToString());  
 Where I get lost is in the declaring of a new sqlcommand and sqlparameter. Can you please spell out where to use this and if I need to change my SQLdataSource. I currently was trying to use it in the OnClick of a button. What I had did the following
 Protected Sub CreateIssue_Click(ByVal sender As Object, ByVal e As System.EventArgs)        dim returnValue as integer        'how do I get a return value from the stored procedure executed in 'insertissue.insert() here to a variable?             InsertIssue.Insert()        Response.Redirect("/addarticletoissue")            End Sub
 
again, thank you for your help and patience with such a beginner =)

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved