Click here to Skip to main content
15,071,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using an SQL Select statement in one of my programs (something I pillaged blindly from the web somewhere) but in truth I don't actually understand the statement completely and cannot seem to get an explanation anywhere (including W3Schools where I do a lot of learning)

VB
Ssql = "SELECT Count(*) as NoOfJustifyRecs FROM Purchase_Justify WHERE PJ_Po_Number = '" & cbo_Order_Number.Text & "'"

       da = New OleDb.OleDbDataAdapter(Ssql, cn)
       da.Fill(ds, "NoOfJustifyRecs")

       cn.Close()


       If ds.Tables("NoOfJustifyRecs").Rows.Count = 0 Then
            ' do something
       End If


Could someone please explain to me the use of 'as NoOfJustifyRecs' ?
Ideally I would like to say something like

VB
If NoOfJustifyRecs = 0 then
  '  do something
EndIf


but obviously NoOfJustifyRecs is not declared.

My big question is what is the point or use of using 'AS NoOfJustifyRecs' when as my code stands I can simply get the value from the dataset.

Thanks guys.
Posted

1 solution

when we run a count(*) statement of any other function in sql server, we get the result with {no column name} as column header of result. By using 'AS NoOfJustifyRecs' you will get the count with column header named as 'NoOfJustifyRecs'.

Run the following on AdventureWorks DB......

select count(*) from Person.StateProvince

Result will be---
(no column name)
181

select count(*) as NoOfJustifyRecs from Person.StateProvince

Result will be---
NoOfJustifyRecs
181


Hope you understand now..
If you have any doubt, please let me know.
   
Comments
Darrell de Wet 1-Jul-13 4:41am
   
Ok, I understand. Thank you very much for the explanation, I appreciate your time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900