SQL Server :: Group By Clause In CTE?

Mar 30, 2011

I have a query with group-by clause. I want to use it in recusionCTE.How is it possible?I want to know the totalamount for each fname done through this query:select top 10 fname,SUM(totamt) as 'Total Amount' from tables_list group by fname order by 'Total Amount' descBut when any person logins he must be able to see this list for his own hierarchy down the line including himself.

View 2 Replies


Similar Messages:

SQL Server :: Aggregate Function In Group By Clause?

Apr 1, 2011

can i use aggregate function in group by clause like below mentioned query (which marked in red color)

[code]....

View 2 Replies

SQL Server :: Can Use Aggregate Function In Group By Clause

Feb 9, 2011

can i use aggregate function in group by clause like below mentioned query (which marked in red color)

[code]....

View 4 Replies

DataSource Controls :: List Duplicate Records And Group By Clause?

May 27, 2010

I have some duplication that I need to clean up. I wrote a SQL query that is supposed to return duplicate customers who are located in the same city and zipcode.

I have 2 questions regarding it:

1. Is the query syntax correct to find duplicate records by same city and zipcode, data is being returned but it just returns the same customer a few times?

2. I only need to do the GROUP BY clause for Fullname and City however it gives an error when the other columns are left out. The error is Address, State and Zip not being in the aggregate function or in the group by clause.

Adding all the remaining columns to the GROUP BY clause works.

Query is as below:

[code].....

View 3 Replies

SQL Server :: Select Statement With Where Clause?

Feb 14, 2011

I have a select statement:

cmd = new SqlCommand("select lab_key from tblorderwhere", connection);

I would like to add a where statement that pass variable to the select statement. How I can do this?

Where lab_key =ChargeFine( that is my variable)

View 2 Replies

SQL Server :: Description About Working Of OVER Clause

Jan 26, 2011

I have created the folowing stored procedure and it is working fine... I have used OVER clause in the query written in the WITH block. Can some body provide description about working of OVER clause and why I need to use it with the ROW_NUMBER() function.

CREATE PROCEDURE SelectOrder
@PageIndex INT,
@PageSize INT
AS
BEGIN
WITH Order AS
(
SELECT ROW_NUMBER() OVER (ORDER BY OrderId DESC)
AS Row, *
FROM Orders
)
SELECT *
FROM Order
WHERE Row between (@PageIndex - 1) * @PageSize + 1 and @PageIndex*@PageSize
END

View 2 Replies

SQL Server :: Case Statement In Where Clause?

Sep 13, 2010

i trying following query Select

View 4 Replies

SQL Server :: Error Converting The Nvarchar Value '1,2,3,4,5,6' To A Column Of Data Type Int - IN Where Clause

Feb 28, 2011

I am using an adapter to get a list with IN where clause as:

[Code]....

I passed the parameter, CatIDList, with string value 1, 2, 3, 4, 5

However, it returns error of Error converting nvarchar value.

View 3 Replies

Access The Group Of A Linq Group - By Query From A Nested Repeater Control?

Mar 26, 2010

I'm using a linq group by query (with two grouping parameters) and would like to use the resulting data in a nested repeater.

var dateGroups = from row in data.AsEnumerable()
group row by new { StartDate = row["StartDate"], EndDate = row["EndDate"] };
"data" is a DataTable from an SqlDataAdapter-filled DataSet. "dateGroups" is used in the parent repeater, and I can access the group keys using Eval("key.StartDate") and Eval("key.EndDate").

Since dateGroups actually contains all the data rows grouped neatly by Start/End date, I'd like to access those rows to display the data in a child repeater. To what would I set the child repeater's DataSource? I have tried every expression in markup I could think of; I think the problem is that I'm trying to access an anonymous member (and I don't know how.) In case it doesn't turn out to be obvious, what would be the expression to access the elements in each iteration of the child repeater? Is there an expression that would let me set the DataSource in the markup, or will it have to be in the codebehind on some event in the parent repeater?

View 3 Replies

C# - Select DataTable (only Some Values) From _GetDisplayData And GROUP Data By Days Where Group Rules Is Different For Different Columns

Mar 4, 2010

Stack-Overflow :3 I've got a kind of hard-case question.

So I'll try clearly explain my idea with my poor english :/ need select to DataTable SOME values from ???_**GetDisplayData **procedure for each day of previos month (GROUP IT) where group rules for different columns is different


I need to select some values in stored procedure from other stored procedure like this :

SELECT X FROM Y_Procedure(@ProcedureParameters)Also I need to select from dynamic SQL Procedure like

Y_Procedure=@Y+'_Procedure'
SELECT X FROM Y_Procedure(@ProcedureParameters)


Also I need to load it to DataTable :-/INSERT INTO @Report (CellHorizontal, CellVertical, CellValue) --to TABLE
SELECT Date,X2,X3 FROM Y_GetDisplayData(@Param)

SET NOCOUNT OFF;
SELECT *
FROM @Report

GetDisplayData works as select with parameters and that doesn't returns SQL DataTable
And there is no way to recode GetDisplayData's procedures, it's just constant procedures for me.Finally I need to Group nodes from this table

INSERT INTO @Report (CellHorizontal, CellVertical, CellValue)
SELECT T1.Date,
IF ((Select grouptype...)=1) T1.X2 + T2.X2
ELSE IF ((Select grouptype...)=2) AVG(T1.X2,T2.X2),
IF ((Select grouptype...)=1) T1.X3 + T2.X3
ELSE IF ((Select grouptype...)=2) AVG(T1.X3,T2.X3),
(SELECT T2.Date,X2,X3 FROM Y_GetDisplayData(@Param) T2
WHERE T2.Date>T1.Date AND T2.Date>=T1.Date)
FROM Y_GetDisplayData(@Param) T1
GROUP BY EVERY DAY ???--and here is epic fail


I can make all stuff on asp server :And C# allows me to use something like SelectCommand = IzmProc + "_GetDisplayData"; And then I will work (select special data) with DataTables on ASP.NET Server but it's better to make all on SQL ... But looking like it's just unrealizable on SQL >_<

I gonna think about C# realization,but my code is very weird , got errors and doesn't works >_<

public static DataTable GetReport(string Param)
{
System.Configuration.ConnectionStringSettings connSetting = ConfigurationManager.ConnectionStrings["FlowServerConnectionString"]; [code].....

View 3 Replies

SQL Server :: Using CASE Statement In "IN" Clause Of Query?

Sep 29, 2010

I have a sql datasource with the ControlParameter called ddlDropDownList.

2 questions:

1. Is my syntax below ok, I am getting a runttime error that the syntax is incorrect.

2. I have the select statement set up the control parameter to get the selected value from the dropdownlist as shown below, is that syntax correct? especially the "selectedItem.value" for the propertyname property.

[Code]....

[Code]....

View 6 Replies

SQL Server :: Sql Could Use Row_number Over For Each Group

Jan 20, 2011

select a.* from (select vip,date,amount,dense_rank() over(order by vip,date) as 'sn' from income ) a where sn = 1

vip date amount sn
0001 2010/1/1 50 1
0001 2010/1/1 10 1
0001 2010/1/6 80 2
0001 2010/1/7 90 3
0002 2010/1/2 40 4
0002 2010/1/5 10 5
0002 2010/1/5 80 5
0002 2010/1/7 90 6

would it possible give it row number for each group? (group by vip) like this

vip date amount sn
0001 2010/1/1 50 1
0001 2010/1/1 10 1
0001 2010/1/6 80 2
0001 2010/1/7 90 3
0002 2010/1/2 40 1
0002 2010/1/5 10 2
0002 2010/1/5 80 2
0002 2010/1/7 90 3

View 2 Replies

SQL Server :: Order When Group By Is Used?

Oct 15, 2010

I have this statement:

[Code]....

The problem is, it is not ordered correctly. How can I order it correctly with earliest datetime on top?

View 5 Replies

SQL Server :: How To Group The Data Query

Dec 22, 2010

I am using SQL Server 2005. I have below table:

CompanyNo CompanyName Product

--------------------------------------------------------

100 C1 P11

100 C1 P12

100 C1 P13

200 C2 P21

200 C2 P22

etc...

And I want my sproc returns like...

CompanyData

------------------

100 - C1 - P11, P12, P13

200 - C2 - P21, P22

etc...

View 3 Replies

SQL Server :: Combining Two Fields With A Group?

Oct 19, 2010

[Code]....

which is giving me

And i tried

select * from @jax

group by rep

and it did not group them. How would i bring the sum ly up with the sum? so it shows 1-10 cust,sum,sumly

View 1 Replies

SQL Server :: Arrange Record By Position In Group?

Jan 7, 2011

I want to develop rotation logic for my company's software by using SQL Query. I will explain you what exactly I want.

As mentioned in above figure (LEFT SIDE) I have 8 grades in alphabetical order A, B, C, D, E, F, G and Z. There are different companies belong with different grades respectively. This is my database table situation. And I want an output like (RIGHT SIDE) figure in my grid view using SQL Query.

The grade position is skipped if there is no any raw or company name exists. And newly entered Company is automatically placed in that respective skipped grade position.

I have attached an sql script for your kind help to make such useful query.

View 13 Replies

SQL Server :: Group By Not Returning Expected Results?

Dec 17, 2010

I have a procedure that is used on a search page.. im trying to provide a highlevel resultset which you can then click on a record to view all records associated with it.

My expectation is to return 5 columns.. the ID and Date is what i want to group on.. so that if there are 10 records for ID=5 and Date=10/25/2010 then in my results i would have 1 record. Once im done with the page, you can then click on that line in the gridview to view the 10 records for that id. Does that make sense?

I have the following query, but for the criteria i entered, im getting back 3 records instead of just 2 since there is a differnet reboot count, BUT i really still just need overall data. so it should be only 1 record and seen below is what is returned and what is expected..

[Code]....

Here are the 3 records..

Currently returned

id Event Date Mount Errors Reboot Count J1939

225 11/01/2010 0 11 0

225 11/01/2010 0 11 0

225 11/01/2010 0 12 0

Expected returned

id Event Date Mount Errors Reboot Count J1939

225 11/01/2010 0 34 0

View 2 Replies

SQL Server :: Group Table Records By Hour For The Last 24 Hours?

Oct 15, 2010

i have a table which records visits to a page, what i want to do is get a count of the last 24 hours and group the visits by the hour.

This is my table structure;

ID, ChannelNewsID, AddDate

This is what i did so far however it gives me both past and future records where as i want 24 hours previously starting from when the query was run. Here is what my query looks like;

[Code]....

View 7 Replies

SQL Server :: How To Group Weekly Data For A Month Days

Sep 16, 2010

how to group weekly data for a month days

View 6 Replies

SQL Server :: Get Unique Page Title - SQL Group And Sort Datetime

Sep 21, 2010

Basically I have a table as follows:

Page Title ¦ DateTime
Home ¦ 20/09/2010 17:25:01
Home ¦ 20/09/2010 16:01:16
Home ¦ 20/09/2010 17:24:01
About Us ¦ 06/09/2010 17:27:01
Home ¦ 03/09/2010 14:25:01
SiteMap ¦ 21/09/2010 17:21:01

I want to get the unique page title but latest date, therefore query result would be:

SiteMap
Home
About Us

View 3 Replies

Web Forms :: Change Validation Group For Server Controls In Code Behind

Aug 6, 2010

I have individual controls with different groups in two separate divs in an aspx page. I am passing a querystring value to this page and on page load depending on the querystring value want to show the divs n change the validation group.

View 2 Replies

Forms Data Controls :: User Group List Like Graph / Get The List Of Users Under A Group

Oct 26, 2010

I need to develop a page in my applicaiton like the image for the user lists.

I need to get the list of users under a group and need to show likw this.

View 4 Replies

Visual Studio :: Group Profiles Settings - Users In The Group Update The Same Settings?

Jan 19, 2010

We have many different clients, and each client can have multiple user accounts.Right now, we have user settings set up on the ASP project, and a WinForms application can see these settings, depending on which user logs into the winforms application. They are specific to the user. I want to make them specific to the client, so users can be in "groups" by their client, and all users in the group would see/update the same settings.

View 1 Replies

Group Section Date Error In Crystal Report After Deployed To A Windows Server 2008?

Jan 27, 2011

This group section cannot be printed because its condition field is nonexistent or invalid. Format the section to choose another condition field. Error in File Detailed_CrystalReport {9C8154B9-5093-457C-9E6A-2A1D63E7E866}.rpt: Invalid group condition.

without group section report can correctly show report and with group section can correctly show in local computer only with visual studio But with group section has error after deploy to new machine window server 2008 group section is date my crystal report version is 2008, assembly version 12, CRDist x64

try 1: i try to delete the group date and run local, it can correctly show date, but deploy to the new machine date is invisible Group date is wrong the date have only 01/25/2011 however group date become 23/1/2011 why group date is not 01/25/2011?

View 1 Replies

Forms Data Controls :: Group Data,- The Group's Header Be On The Top ?

Feb 5, 2010

I'd like to gruop data from a table, for example, by DATE or CATEGORY, something like this:
29/01/2010
News 1
News 2
News 3

30/01/2010
News 1
News 2
News 3

or group by CATEGORY, like this:

ASP.NET
News 1
News 2
News 3

PHP
News 1
News 2
News 3

View 4 Replies







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