|
Thanks for the reply but no joy:
Cannot use an aggregate or a subquery in an expression used for the group by list of a GROUP BY clause.
|
|
|
|
|
Sorry,
My mistake. Try this group by clause:
Group by u.Email, u.FirstName + ' ' + u.LastName
Wout Louwers
|
|
|
|
|
Can anyone else offer any more on this? Sorry for the spam but it's quite urgent. I've tried playing about with it more by placing the case inside the JOIN - which I got my hopes up about but still the same result of recieving multiple user rows with different worklogs
ALTER procedure [dbo].[GetAllUsersWhoHaventSubmittedTimeForWeek]
(
@MinimumHours float,
@EndDate datetime,
@AmountOfDaysBack int
)
as
begin
SELECT u.Email,
u.FirstName + ' ' + u.LastName AS Usersname,
w.WorkDone
from Users u LEFT OUTER JOIN
(
Select UserID,
WorkUnitTypeId,
CASE WorkUnitTypeId
WHEN 1 THEN ISNULL(round(sum(WorkDone / 60),1), 0) --Minutes
WHEN 2 THEN ISNULL(round(sum(WorkDone),1), 0) --Hours
WHEN 3 THEN ISNULL(round(sum(WorkDone * 24),1), 0) --Days
WHEN 4 THEN ISNULL(round(sum(WorkDone * 168),1), 0) --Weeks
ELSE 0
END as WorkDone
FROM worklog
WHERE WorkLogDateTime >= dateadd(d, -@AmountOfDaysBack, @EndDate) and WorkLogDateTime <= dateadd(d, 1, @EndDate)
--HAVING round(sum(WorkDone) / 60, 1) < @MinimumHours
GROUP BY UserId,
WorkUnitTypeId
) w
ON u.UserId=w.UserId
WHERE u.userid not in (SELECT User_ID FROM ReportUsers WHERE Status = 0) and u.isactive = 1
GROUP BY w.UserId,
u.FirstName,
u.LastName,
u.Email,
WorkUnitTypeId,
WorkDone
ORDER BY sum(WorkDone) DESC
END
|
|
|
|
|
Try this
ALTER procedure [dbo].[GetAllUsersWhoHaventSubmittedTimeForWeek]
(
@MinimumHours float,
@EndDate datetime,
@AmountOfDaysBack int
)
as
begin
SELECT u.Email,
u.FirstName + ' ' + u.LastName AS Usersname,
w.WorkDone
from Users u LEFT OUTER JOIN
(
Select UserID,
Sum(CASE WorkUnitTypeId
WHEN 1 THEN ISNULL(round(sum(WorkDone / 60),1), 0) --Minutes
WHEN 2 THEN ISNULL(round(sum(WorkDone),1), 0) --Hours
WHEN 3 THEN ISNULL(round(sum(WorkDone * 24),1), 0) --Days
WHEN 4 THEN ISNULL(round(sum(WorkDone * 168),1), 0) --Weeks
ELSE 0
END) as WorkDone
FROM worklog
WHERE WorkLogDateTime >= dateadd(d, -@AmountOfDaysBack, @EndDate) and WorkLogDateTime <= dateadd(d, 1, @EndDate)
--HAVING round(sum(WorkDone) / 60, 1) < @MinimumHours
GROUP BY UserId
) w
ON u.UserId=w.UserId
WHERE u.userid not in (SELECT User_ID FROM ReportUsers WHERE Status = 0) and u.isactive = 1
GROUP BY w.UserId,
u.FirstName,
u.LastName,
u.Email,
WorkUnitTypeId,
WorkDone
ORDER BY sum(WorkDone) DESC
END
|
|
|
|
|
[deleted]
Got it working! Bascilly deleted it and started again and managed to get it working from the advice you both gave (Wrapping the case in a sum and removing Workunittypeid from the top level group by).
Thanks for the help - first and last stored procedure I attempt
modified on Thursday, August 6, 2009 5:45 AM
|
|
|
|
|
Hi,
How we can design a database tables that record hierarchical data. The levels of hierarchy are not fixed. For example:
Table Header:
A B C D E F G SomeOtherHeader
Respective record:
1 4 3 2 6 t a PK_of_Another_Table
2 3 4 6 8 y a PK_of_Another_Table
Now the record has upto Level "G" with different values. But it can be up to different level for another block of record.
So what is best relational implementation of this Dynamic Hierarchy?
Please refer any link that is worth reading related to this topic.
Thanks.
Good Day.
|
|
|
|
|
Hello,
I am developping ASP.NET 2008. My data is stored in SQL server 2008.
The problem is when I query, I got 0 records and this is because the data is stored in hebrew.
I tried to change the collation property in Column of the table but it doesn't help
Please help
Shay Noy
|
|
|
|
|
Hi--can you post your code so we can see if it might be something with that?
|
|
|
|
|
Private Function GetPathPicturesFromDb(ByVal Period As String, ByVal Location As String) As String
Dim ds As New DataSet("Pictures")
Dim strSQL As String = "SELECT FullFileName FROM PicturesTable " & _
"WHERE PERIOD='" & Period & "' " & _
"AND LOCATION='" & Location & "'"
Dim sqlConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("MemberShipConnectionString").ConnectionString)
sqlConnection.Open()
Dim da As New SqlDataAdapter()
da.SelectCommand = New SqlCommand(strSQL, sqlConnection)
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then _
Return ds.Tables(0).DefaultView(0).Row("FullFileName").ToString.Trim
Return ""
End Function
The Location field contains hebrew words and when I am querying by changing the database content in english it works perfectly with the same code I post upstair. So I am sure that the problem is because the hebrew. I need to config anywhere that the Location column can contain hebrew characters. Again, I success to insert hebrew words in the databse but when I am querying no records are found
Thanks
Shay Noy
|
|
|
|
|
shaynoy wrote: The problem is when I query, I got 0 records and this is because the data is stored in hebrew.
How do you know that is the problem? AFAIK, if table has records, query will return irrespective of the type of data. Are you sure the table has records? What data type are you using for keeping values?
|
|
|
|
|
This is a new table that I insert record in it and yes I am sure there are records and i am sure that my query is OK. I just need to know how to config the column that store hebrew characters to get abiility for query on it
Shay Noy
|
|
|
|
|
hi guys please help me.
while connecting to oracle database it shows the following error.
The ORA-01033: ORACLE initialization or shutdown in progress
i tried to login from command prompt..
c:\sqlplus/nolog
sql:\connect sys/manager as sysdba
but is throws error:- "insufficient privileges".
cannot connect to Database.....
i restarted all oracle services.
but the same error continues.....
from last 2 days it is showing the same error.
|
|
|
|
|
Have you logged onto OS as owner of Oracle software?
|
|
|
|
|
Hi,
I would like to load(import) data from my non-unicode database backup files to Unicode database instance in SQL Server 2005.
How to achieve the above requirement? if anyone knows the steps, it would be highly appreciated.
Thanks,
Sadhik
|
|
|
|
|
Try googling for Sql Server 2005 DTS
|
|
|
|
|
Error: saving tester - TST-000-341 - item :: System.Data.SqlClient.SqlException: Invalid column name 'TST'.
update tbl_swbom_checklist_testers set passfail='No' where package=992-700-358 and tester=TST-000-341
That is part of the exception thrown by my web app. There is no column named TST, the column is named TESTER, which is why the SQL statement is 'where tester=TST-000-341'. The PACKAGE column is the same syntax and it has no complaints. What am I missing here? Here is my entire SP:
CREATE PROCEDURE dbo.sp_UpdateTesterColumn
(
@PACKAGE nvarchar(255),
@TESTER nvarchar(100),
@COLUMN nvarchar(100),
@VALUE nvarchar(100),
@LASTCHANGEBY nvarchar(100)
)
AS
declare @sql nvarchar(1024)
set @sql=''
set @sql=@sql+'update tbl_swbom_checklist_testers set '+@COLUMN+'='''+@VALUE+''' '
set @sql=@sql+'where tester='+convert(nvarchar(100),@tester)+' and package='+convert(nvarchar(255),@package)
print @sql
exec sp_executesql @sql
GO
Obviously the print is when I uncomment the print statement. What am I missing here?
|
|
|
|
|
Change
cdietschrun wrote: package=992-700-358 and tester=TST-000-341
with
package='992-700-358' and tester='TST-000-341'
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
I thought so, but that code is generated by the SP, and I am having trouble with the quotation/apostrophes that properly encase each one. Could you help me and show me how to edit the SP itself?
|
|
|
|
|
set @sql=@sql+'update tbl_swbom_checklist_testers set '+@COLUMN+'='''+@VALUE+''' '
set @sql=@sql+'where tester='''+convert(nvarchar(100),@tester)+''' and package='''+convert(nvarchar(255),@package)
set @sql=@sql+''''
Ended up looking like that, if anyone was curious.
|
|
|
|
|
Instead using four single quotes then use CHAR(39)
set @sql=@sql+'update tbl_swbom_checklist_testers set '+@COLUMN+'='+CHAR(39)+@VALUE+CHAR(39)<br />
set @sql=@sql+' where tester='+CHAR(39)+convert(nvarchar(100),@tester)+CHAR(39)+' and package='+CHAR(39)+convert(nvarchar(255),@package)+CHAR(39)
Hope this helepd you.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
modified on Tuesday, August 4, 2009 11:56 AM
|
|
|
|
|
Hi All,
i want to edit DataSet value before binding to GridView. How can i do that..?
conn.open();
string result="select name,address,age";
sqlCommand cmnd=new sqlCommand(result);
sqlDataAdapter ad=new sqlDataAdapter(result,conn);
DataSet ds=new DataSet();
result.Connection=conn;
ad.SelectCommand=result;
// in here i want to edit (divide age value by 2) before bind data to gridview.
ad.fill(ds);
GridView1.DataSource=ds;
GridView1.DataBind();
conn.close();
i want to divide age value by 2 before bind data to gridview.How can i do that...???
Thank you very much .....
CheeN
|
|
|
|
|
A DataSet object is a collection of DataTable objects. You could loop through the table and update the age with something like this:
For Each row As DataRow In ds.Tables(0).Rows<br />
row("age") = row("age") / 2<br />
Next
Or you could just do it in the select by changing your select statement to this string:
"select name, address, age/2 as age"
Hope this helps.
|
|
|
|
|
Thank u 4 your post. I fixed my problem..Thank u all...
CheeN
|
|
|
|
|
For Each dr As DataRow In ds.Tables(0).Rows
dr("ColumnName") = (dr("ColumnName") / 2)
Next
Where ColumnName is your data column in the DataSet Table.
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
Hi Guys,
I'm in need of your help.
my problem is, i have two tables namely MASTER and LINECONTENT.
"MASTER" table contains 5,00,000 records,
The columns in MASTER table is
masterid int, masterdesc varchar(1000).
"LINECONTENT" table contains more than 1000 records &
its columns are pageno int, lineno int, content varchar(2000).
I want to compare each row of "MASTER" table, masterdesc column value with the "LINECONTENT" table content column,
If any records matched i want to take the matched master record and store it in another table.
for this i used the below query.
select b.* from linecontent a
join master b on a.content like '%'+b.masterdesc+'%'
but this query is taking much. more than 15 minutes
i want to decrease the time give me some suggestions handle this problem
thank you
regards,
prakash
|
|
|
|
|