BobRodes's Profile
Reputation: 545
Enlightened
- Group:
- Expert
- Active Posts:
- 2,917 (2 per day)
- Joined:
- 19-May 09
- Profile Views:
- 22,734
- Last Active:
Today, 01:31 PM- Currently:
- Offline
Previous Fields
- Country:
- US
- OS Preference:
- Mac
- Favorite Browser:
- Safari
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- XBox
- Your Car:
- Mercedes
- Dream Kudos:
- 0
- Expert In:
- VB6/VB.NET
Latest Visitors
-
kentlucky 
08 May 2013 - 06:46 -
RandomlyKnighted 
06 May 2013 - 16:21 -
Kaito1412 
05 May 2013 - 21:06 -
macosxnerd101 
01 May 2013 - 22:17 -
jayveeeeeee 
21 Apr 2013 - 19:43
Posts I've Made
-
In Topic: What is a short version of this code? Group by day and another field.
Posted 19 May 2013
What you're saying is that you want to eliminate duplicate values first, and then count the result. To do this, use the DISTINCT keyword in your nested select, and then do the count on the result. So, like this:SELECT tt.PrimaryID, DATEPART(MONTH, TestDate) AS [Month], Count(tt.TestDate) FROM (SELECT DISTINCT PrimaryID, TestDate FROM ThisTable) tt GROUP BY PrimaryID, DATEPART(MONTH, TestDate)
In other words, yes, there is as you suspect a short version of your code.
-
In Topic: COUNT in an sql querry
Posted 19 May 2013
Count counts how many records you have. It doesn't "count" the numbers in the fields. It also doesn't include null values the way you have it. So, you would use count to find the number of records that have a value in each column that you are counting. That's obviously not what you want to do; you want to add the values in each column. That's sum, not count.
Next, if you want them by Month, that's where Group By comes in. Look up the datepart function, include it at the beginning of your select query as a column, and include the same function in your group by clause. -
In Topic: Fill in a null column when data is submitted on sql server 2008
Posted 19 May 2013
You're able to stick a literal value into a select query: SELECT Title, Price, 1 from tblCart. (This will tack a column on the end of your query result that always has the value of 1.) So, for your line 5:String cmdString = "INSERT INTO tblPurchaseItem(Title, Price) Select Title, Price, " + purID + " from tblCart";
Assuming that purID is an integer. If not, you'll have to enclose the variable in single quotes:String cmdString = "INSERT INTO tblPurchaseItem(Title, Price) Select Title, Price, '" + purID + "' from tblCart";
which you can do anyway if you like. -
In Topic: Execution Plan
Posted 19 May 2013
You can put two different ways to execute the same query side by side, and the execution plan will tell you what percentage of time each one will take. -
In Topic: entity relationship diagram for eprint repsitory database
Posted 19 May 2013
Why don't you ask eprints? www.eprints.org has an email for requests like this.
My Information
- Member Title:
- Your Friendly Local Curmudgeon
- Age:
- 56 years old
- Birthday:
- September 15, 1956
- Gender:
-
- Location:
- Tullahoma, Tennessee
- Interests:
- IT, Music.
- Forum Leader:
- VB6, VB.NET
- Full Name:
- Bob Rodes
- Years Programming:
- 25
- Programming Languages:
- BASIC, VB6, VB.Net, C#, Java, Javascript, CSS, also UML
Contact Information
- E-mail:
- Click here to e-mail me
|
|


Find Topics
Find Posts
View Reputation Given




|
Comments
lucky3
31 Dec 2012 - 02:30Elda
23 Jul 2012 - 19:09trevster344
15 Jun 2012 - 17:5315Dhan
01 May 2012 - 18:15haidar976
18 Aug 2011 - 23:55You are expert man
BobRodes
15 Feb 2011 - 15:02Dogstopper
14 Feb 2011 - 19:35