Sql Server Query To Group Records?
May 9, 2011
i would like to select from the following table:
PostTable
feed dateinserted count
box1 2011-05-28 11:00 1000[code].....
the total number of records for the previous day where the feed is, 1, 3 and 5 i.e.the feeds I need to retrieve totals for will just be selected based on what I need for instance it could be box4 and box 5...not specifically odd and even...I hope this makes it more clearer..what I have for all records:
select sum(count) as [total] from PostTable where Cast(dateinserted as DATE) =
CAST(getdate()-1 as DATE)
View 3 Replies
ADVERTISEMENT
Dec 9, 2010
I am trying to accomplish the following:
SELECT Table1.prod_code, SUM(Table1.prod_bal) AS TotalProdBalance
FROM Table1
LEFT OUTER JOIN Table2 ON Table1.prod_code = Table2.prod_code
WHERE Table2.prod_code IS NULL
GROUP BY Table1.prod_code
HAVING (SUM(Table1.prod_bal) <> 0)
How to translate this to Linq using VB.net syntax?
View 1 Replies
Jun 12, 2011
I am a Newbie using SQL server and vb.net in VS2010. I am re-writing an existing application which is written in an old programming language. I have a table with invoice records waiting to be assigned an invoice number and invoice date. I have two ways of updating these records , the first way is the user manually selects which records/rows to be updated for a specific customer account number. This all works fine.
I am trying to write a stored proc which goes through all un-invoiced records (i.e., invoice number = blank) , it is to group records/rows by account number and assign next invoice number (which I already have astroed proc to fetch) and then when the account number changes to move onto the next batch of records for the next account.
View 2 Replies
May 25, 2009
I am looking to produce an Excel report from an Access database table. The data contains numerous records with fields for Site, Country, Region, Type and a Resolution Time. My problem is that each month the Sites change so I need to be able to write VB code within Access to read the database table and output 'Site' records for that month, grouped together along with the incident details for that site, e.g. The report would have the following headings:
'SITE' 'COUNTRY' 'REGION' 'TYPE' 'TOTAL' 'RESOLVED<3DAYS' 'RESOLVED>3DAYS' 'NOT RESOLVED'
MEL AUS APAC TECHNICAL 78 40 31 7
MEL AUS APAC HARDWARE 49 40 8 1
LON GBR EURO HARDWARE 90 40 40 10
As I will have over 30 different sites and these may change each month how do I loop through the data identifying each site and its associated field values? I have used the following code to open the data and loop through records printing to excel, but am stuck at grouping by site:
Set rst = db.OpenRecordset(sqlStat)
row=10.......
..... Do While Not rst.EOF
.cells(row, 1).Value = rst.Fields(0)
.cells(row, 1).Value = rst.Fields(1)
.cells(row, 1).Value = rst.Fields(2)...
View 1 Replies
Jun 12, 2011
how do I customize my Datareport? I want to group my data based on field value.This are my table fields;
SubCode, Description, Units, Grade, Year, Semester
I want to group records based on the Year value. There should be a different table for records whose Year = 1st Year, 2nd year, 3rd Year etc... (Guys this is in printing, OK?)
View 1 Replies
Aug 26, 2009
I have a table DailyTransaction in MsAccess as under: DTDate, DTTime, CustId, Description, Quantity, Price, Amount, AccountNumber, Name I want to extend following query with a Group By clause:I require to display all records in a Listview Group By CustId.Then I require to display all records in a Listview Group By AccountName.e how I can extend following query with Group By clause to achieve the required results
View 4 Replies
Dec 23, 2009
I have the following query that groups parking spaces by their garage, but I can't figure out how to iterate the data in the view.
Public Function FindAllSpaces() Implements ISpaceRepository.FindAllSpaces
Dim query = _
From s In db.spaces _
Order By s.name Ascending _
[code]....
The controller is taking the query object as is and putting it into the viewdata.model and as stated the view is not currently strongly typed as I haven't been able to figure out how to do this. I have run the query successfully in linqpad.
View 2 Replies
Apr 14, 2010
I have a listview in which the View is set to Details. I have a module with a Sub that accepts a Listview and a sql query as arguments:
Public Sub PopulateListView(ByVal lvw As ListView, ByVal filtersql As String)
Dim li As New ListViewItem
Dim lvwColumn As ColumnHeader
Dim counter As Integer
[Code] .....
This is how I call the sub:
PopulateListView(lvwTranHistory, "SELECT AccountID,TransactionDate,TransactionAmt FROM [Transactions] WHERE GameSheetID = " & CurGameSheetID & ";")
I tried some stuff there to group by the accountid but it ain't working. How to get the grouping to work.
View 1 Replies
Nov 4, 2010
The following data is created by joining two sql tables together:I would like to group together distinct rows of DateStamp/UserName/ StudentName/ InstructorName/TableName/PrimaryKey (I'll call this 'group records') and then group under these ColumnName/PreviousValue/NewValue (I'll call this 'subgroup records')The end result would be that I could iterate through the 'group records' - there would be 5. In each 'group record', I could then iterate through the 'subgroup records'. The 5 groups would contain 3, 2, 5, 2 and 1 subgroup records respectively.What would be the syntax to create a query to do this? Ideally this would be in a vb.net linq syntax.
View 1 Replies
Sep 28, 2010
How do I order by and group by in a Linq query?I tried..Dim iPerson = From lqPersons In objPersons Where Len(lqPersons.Person) > 0 Group lqPersons By key = lqPersons.Name Into Group Order By Group descending Select Group, key
For Each i In iPerson
tmp = tmp & vbNewLine & i.key & ", " & i.Group.Count
Next
[code].....
View 5 Replies
Feb 24, 2010
how i can get a list of users who are members of a group in Active Directory. A vb.net example would be great. I can list all users in AD, but cannot get just the users in a group.
Also do anybody know of a really easy tutorial on LDAP queries with vb.net examples.
View 1 Replies
Aug 24, 2009
I am trying to do a simple summary of table data using a LINQ query.a regular SQL Query looks like:[code]This query works fine and returns the correct results.[code]This LINQ query returns the incorrect results some of the time. Off by .01 in most cases.The "value" column is of type Numeric (12,2) in the database.Now when I show the values from the Sum in a msgbox I get extra precision and thus incorrect results as my end result because of rounding.For example I get 835.18 + 54.62 = 889.80960 from the above LINQ query.I am running Visual Studio 2008 9.0.30729.1 SP on Vista 64Bit with .NET 3.5 SP1.
View 3 Replies
Jul 26, 2010
My LINQ query contains the following Group By statement:
Group p By Key = New With { _
.Latitude = p.Address.GeoLocations.FirstOrDefault(Function(g) New String() {"ADDRESS", "POINT"}.Contains(g.Granularity)).Latitude, _
.Longitude = p.Address.GeoLocations.FirstOrDefault(Function(g) New String() {"ADDRESS", "POINT"}.Contains(g.Granularity)).Longitude}
The query works, but here is the SQL that the clause above produces
SELECT [t6].[Latitude]
FROM (
SELECT TOP (1) [t5].[Latitude]
[Code]....
but this produced an error: "A group by expression can only contain non-constant scalars that are comparable by the server."
View 1 Replies
Feb 28, 2012
I have the following SQL query to return all Customers who have no OrderLines with no Parts assigned - i.e. I only want the customers within which every order line of every order has no parts assigned - (in the actual problem I am dealing with a different domain but have translated to customers/orders to illustrate the problem)
SELECT c.Customer_PK
FROM Customers c
INNER JOIN Orders o[code].....
This works but generates less than optimal SQL - it is doing a subquery for Count on each row of the customers query rather than using Group By and Having. I tried making the LINQ Group By syntax work but it kept putting the filter as a WHERE not a HAVING clause.Edit in response to Answers below: I am accepting JamieSee's answer as it addresses the stated problem, even though it does not produce the GROUP BY HAVING query I originally had.I am a VB developer so I have had a crack translating your code to VB, this is the closest I got to but it does not quite produce the desired output:
Dim qry = From c In context.Customers
Group Join o In context.Orders On c.Customer_PK Equals o.Customer_FK
Into joinedOrders = Group[cod].....
The problem I had is that I have to push "jl" into the Group By "Key" so I can reference it from the Where clause, otherwise the compiler cannot see that variable or any of the other variables appearing before the Group By clause.With the filter as specified I get all customers where at least one order has lines with no parts rather than only customers with no parts in any order.
View 3 Replies
Apr 29, 2012
I'm trying to find a way where i can make it loop through the results of my capture group regex query.
For instance if i have this:
VB.NET
Dim matches = Regex.Matches("<h1><span>test</span></h1>", "(?<=<h1>(<span>)?)(?<data>.+)(?=(</span>)?</h1>)")For Each item In matches.OfType(Of Match)()Console.WriteLine(item.Value)Next
And i'm trying to get the contents of <data>, how do i do it without it printing out the junk before it and after it?
quantifier isn't working, its supposed to make the <span> tag optional in the query, but it isn't.
View 2 Replies
Oct 26, 2011
I have these objects:[code]Using LINQ I need to take a List(Of MakeInfo) and a List(Of ModelInfo) and aggregate the StockInfo from ModelInfo into the List(Of MakeInfo).So for each MakeInfo I will have a total count of all stock where MakeInfo.Name = ModelInfo.Make, and also a minimum price.I think it's going to be something like this, but I'm having trouble accessing the nested object and not sure if it's going to be possible with a single query.[code]
View 2 Replies
Apr 16, 2009
I am using VB2005 ASP/VB. I have a Gridview placed on a web form which is popluated by a query based on user input.select * from view_main where initials = ddlfilter.textThis works fine. However I want to display a realtime record count based on that query and dump the info in a label called 'recordcount' which appears at the bottom of the grid.
View 4 Replies
Apr 8, 2012
I have a query that I am running and it will on occasion return zero records.
This is perfectly fine for me, but how do I handle this to avoid throwing an exception?
View 6 Replies
Dec 2, 2010
HI would like to count all the records in my query below and output the results to a text box. [code]...
View 3 Replies
Oct 28, 2010
I am trying to debug my code, which involves a simple webservice that passes parameters to a data class, which calls a stored proc, and returns one row of record. I am not getting any error messages, but I am not getting any records back either.[code]
View 1 Replies
Apr 6, 2008
Im using VB 2008 express but dw any code i get ill just use the tool 2008 has to put the code in 2008.Anyways what im trying to do is make a chat program for about 100-200.How can i get a server on my comp so i can update the list of usernames of passwords without updating the program? How can i get the program on there PC to check my server on my comp if there input is validate? How can i get several users into the chat?How can i get it to display there names when they join the chat and get it to disappear when they leave?
View 14 Replies
Feb 13, 2010
I want to search my access database and count the number of records in the column "Type" in each group. For example
[Code]....
View 7 Replies
Aug 17, 2009
How can i execute my query to insert records in tables?[code]...
View 7 Replies
Apr 29, 2011
Private Sub cmdLogin_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdLogin.Click
Dim conn As MySqlConnection
[Code]....
i supposed it can show the result of count(ID), in this instant it is the number of records count on the OUTBOX so the debug.writeline is RESULT, instead of now it is showing "SELECT COUNT(ID) FROM OUTBOX"
View 2 Replies
Oct 19, 2011
I'm getting an error on my index simply setting a string field prior to using it and entering the loop. When I set this field within the loop I get a error still. how to go about Inserting records based upon a query in vb .net? The following is the code that I have:
Public Sub Insert_RunsizeUPCs()
Dim Command As SqlCommand
Dim adapter As New SqlDataAdapter
Dim dsin As New DataSet
[code]....
View 2 Replies
Mar 18, 2012
I need to add a gridview to my page where the sqldatasource is based on a query that returns records that fall between Sunday and Saturday of the current week. (Each record has one date field) The records are for payroll purposes and the payroll week runs from Sunday to Saturday. I need to find all records that fall in the current pay week.
View 2 Replies
Apr 11, 2011
I am using vb.net and sqlite as database. I am using below scenario to insert multiple records in database using a single query.
INSERT INTO TableName (FirstCol, SecondCol)
SELECT 'First' ,1
UNION ALL
SELECT 'Second' ,2
UNION ALL
SELECT 'Third' ,3
[Code] .....
For less records it is working very well.But when I am inserting about 800 records at a time, executenonquery is throwing the following exception:
SQLite error
Too many terms in compound SELECT.
View 7 Replies
Mar 18, 2010
I am using datarepeater on my windows form to populate records from a temp table. I want to write query to insert records for an employee in a single row rather than multiple rows. For example: I am displaying records of one month only. so i know the definite number of columns. Normally if we use select * from Temp ' it will display and i can populate in a datagrid.
[Code]...
View 1 Replies
Aug 27, 2010
I am new to VB.net and want to know how I can execute SQL queries from within VB.net code. Example: I want to update some records in a table using SQL query on the Form Load event.
View 2 Replies
Nov 22, 2010
I need to do a query in which I can find all records in a table in which a user enters a search word. The word to be searched for will be a word in a column. If there's a table named solutions and in the table there is a field named description; i need to be able to pull up all records where for example the search word is 'printer' is in the description column. I don't have any code or database structure to show. I first need to know if this can be done. Can someone supply a code snippet example or tell me what SQL keywords will do this, or some pointer?
View 4 Replies