|
My sql function is
ALTER FUNCTION[dbo].[FN_ATTENDANCE_REPORT_DATES] ( @EMPID varchar(50) ,@FROMDATE datetime,@TODATE
datetime)RETURNS TABLE
AS RETURN(
SELECT DR_EmployeeID AS EMPID,EM_FirstName+EM_MiddleName+EM_LastName AS EMPNAME,ED_Department AS DEPARTMENT,
ISNULL(CONVERT(VARCHAR,DR_TimeIn,103),'Not checked')AS DATEOFWORK,
SUBSTRING(CONVERT(VARCHAR,ES_TimeIn,9),14,15)+'-'+SUBSTRING(CONVERT(VARCHAR,ES_TimeOut,9),14,15)AS
SHIFTTIME,
ISNULL(SUBSTRING(CONVERT(NVARCHAR,MIN(DR_TimeIn), 22), 10, 11),'Not checked')
AS FIRSTTIMEIN,
ISNULL(SUBSTRING(CONVERT(NVARCHAR,MAX(DR_TimeOut), 22), 10, 11),'Not checked')
AS LASTTIMEOUT,
ISNULL(CONVERT(VARCHAR(5),DATEDIFF(SS,DR_TimeIn,DR_TimeOut)/3600)
+':'+
CONVERT(VARCHAR(5),DATEDIFF(SS,DR_TimeIn,DR_TimeOut )%3600/60)
+':'+
CONVERT(VARCHAR(5),(DATEDIFF(SS,DR_TimeIn,DR_TimeOut)%60)),'0 ')AS TOTALHOURS
FROM
SG_Daily_Register INNER JOIN SG_Emp_Shift ON SG_Daily_Register.DR_ShiftID=SG_Emp_Shift.ES_ShiftID
INNER JOIN SG_Emp_Master ON SG_Daily_Register.DR_EmployeeID=SG_Emp_Master.EM_EmployeeID
INNER JOIN SG_Emp_Department ON SG_Emp_Master.EM_DeptID=SG_Emp_Department.ED_DeptID
WHERE DR_EmployeeID=@EMPID AND CONVERT(VARCHAR,DR_TimeIn,101) BETWEEN @FROMDATE AND @TODATE
GROUP BY
DR_EmployeeID,EM_FirstName+EM_MiddleName+EM_LastName,ED_Department,ES_TimeIn,ES_TimeOut,DR_TimeIn,DR_TimeOut
)
I got output as
FIRSTTIMEIN LASTTIMEOUT
2833020 PreethyS Development 02/12/2010 7:00:00:000PM-3:00:00:000AM 7:10:09 PM 9:40:45 PM 2:30:36
2833020 PreethyS Development 02/12/2010 7:00:00:000PM-3:00:00:000AM 10:20:32 PM 12:15:27 AM 1:54:55
2833020 PreethyS Development 03/12/2010 7:00:00:000PM-3:00:00:000AM 12:23:25 AM 1:24:23 AM 1 :58
2833020 PreethyS Development 03/12/2010 7:00:00:000PM-3:00:00:000AM 1:32:43 AM 3:45:54 AM 2:13:11
But I have to get output as
2833020 PreethyS Development 02/12/2010 7:00:00:000PM-3:00:00:000AM 7:10:09 PM 12:15:27 AM 4:26:26
2833020 PreethyS Development 03/12/2010 7:00:00:000PM-3:00:00:000AM 12:23:25 AM 3:45:54 AM 3:14:09
pls help
|
|
|
|
|
could do with knowing the following
1. what version of SQL?
2. Sample Data
3. Tables (DDL)
As barmey as a sack of badgers
|
|
|
|
|
This is the 3rd question on the same topic. You should stick to 1 thread for 1 topic. Ive also pointed out the forum guidlines which ask you to use descriptive subject lines . "sql function" does not qualify as descriptive in a sql forum. The forum guidlines should also include the request to put code within formatted code blocks for ease of reading (if it doesnt it should).
Furthermore, you have not given any response to the answers youve been given below, so we have no idea if were even on the right track.
Lastly, Ive already answered this question below.
|
|
|
|
|
I required only time in select query from datetime field in format like:
2:20:55 AM.
Pls help me
|
|
|
|
|
That is presentation logic, use your presentation layer to format a datetime instance appropriately.
This should start you off:
var now = DateTime.Now;
Console.WriteLine(now.ToString("h:mm:ss"));
More info: Date / Time format strings[^]
edit: read the forum guidlines for posting messages; pay specific attention to the subject line requirements.
|
|
|
|
|
He may have a specific (and valid) reason for needing times in his sql.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
I highly doubt it. See his post below this one.
In addition, I cannot think of a valid reason to format a date, or time, into a string in sql. can you?
|
|
|
|
|
I don't have a problem with the splitting of the date/time I can think of a number of valid reasons to do that in SQL. What had I missed was that he had stored the data as text, I assumed it was datetime.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
There are a number of ways you can do this.
Here is one:
select convert(nvarchar, getdate(), 8) TheTime
Here is another:
select substring(convert(nvarchar, getdate(), 22), 10, 11) TheTime
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
FIRSTTIMEIN LASTTIMEOUT
7:10:09:000PM 9:40:45:000PM
10:20:32:000PM 12:15:27:000AM
From this,i will have to get only 7:10:09:000PM as FIRSTTIMEIN and 12:15:27:000AM as LASTTIMEOUT.I used min and max function.but it was not possible.help me
|
|
|
|
|
MIN and MAX are indeed the right functions to use, however, for them to work properly the data must be stored in a DATETIME field, because using strings to store those times will obviously yield string-based results for min & max. There is no way to calculate the min and max times from strings representing dates.
Secondly, in order ot know that 12:15am is after 7:10pm you must also store the date date part along with the time part.
Here is a simple test script that shows the process (and returns the results you want). You'll notice ive used yesterdays date for the 3 values before midnight, and today's date for the one after midnight.
WITH data(firstTimeIn,lastTimeOut )
AS
(
SELECT CAST('4 july 2010 7:10:09:000PM' AS DATETIME),CAST('4 july 2010 9:40:45:000PM' AS DATETIME)
UNION
SELECT CAST('4 july 2010 10:20:32:000PM' AS DATETIME),CAST('5 july 2010 12:15:27:000AM' AS DATETIME)
)
SELECT
MIN(firstTimeIn) as firstTimeIn,
MAX(lastTimeOut) as lastTimeOut
FROM data
Result:
firstTimeIn: 2010-07-04 19:10:09.000
lastTimeOut: 2010-07-05 00:15:27.000
|
|
|
|
|
If at all possible don't use that string format. It will break in other locales.
'2010-07-04 22:20:32:00' is the better format. It is always parsed correctly no matter what the locale.
Jason S Short, Ph.D.
VistaDB Software, Inc.
|
|
|
|
|
JasonShort wrote: It is always parsed correctly no matter what the locale.
You don't say! I was providing test data for the OP, which incidentally will parse in all locales as the month names are fully qualified.
|
|
|
|
|
SELECT DISTINCT DATEOFWORKS,EMPNAME,DEPARTMENT,SHIFTTIME,FIRSTTIMEIN,LASTTIMEOUT,WORKINGHOURS,BREAKDURATION
from [dbo].[fn_emp_Workdetails]('2833409','9/25/2010','9/26/2010')INNER JOIN
[dbo].[fn_FirstTimeIn_LasttimeOut] ('2833409','9/25/2010','9/26/2010') ON
[dbo].[fn_emp_Workdetails].EMPID=[dbo].[fn_FirstTimeIn_LasttimeOut].EMPLID
INNER JOIN [dbo].[fn__Emp_Working_Hrs]('2833409','9/25/2010','9/26/2010') ON [dbo].[fn_emp_Workdetails].EMPID=
[dbo].[fn__Emp_Working_Hrs].EMPLOYEE_ID INNER JOIN [dbo].[fn__Break_Duration]('2833409','9/25/2010','9/26/2010')
ON [dbo].[fn_emp_Workdetails].EMPID=[dbo].[fn__Break_Duration].EMPLOY_ID
In this stored procedure,the output is
25/09/2010 NithaV.G Development 7:00:00:000PM- 3:00:00:000AM 7:12:09:000PM 12:45:09:000AM 2:15:17 0:21:-24
25/09/2010 NithaV.G Development 7:00:00:000PM- 3:00:00:000AM 12:59:59:000AM 3:15:16:000AM 2:15:17 0
25/09/2010 NithaV.G Development 7:00:00:000PM- 3:00:00:000AM 12:59:59:000AM 3:15:16:000AM 2:15:17 0:21:-24
25/09/2010 NithaV.G Development 7:00:00:000PM- 3:00:00:000AM 12:59:59:000AM 3:15:16:000AM 5:12:24 0
26/09/2010 NithaV.G Development 7:00:00:000PM- 3:00:00:000AM 7:12:09:000PM 12:45:09:000AM 2:15:17 0
26/09/2010 NithaV.G Development 7:00:00:000PM- 3:00:00:000AM 7:12:09:000PM 12:45:09:000AM 5:12:24 0
26/09/2010 NithaV.G Development 7:00:00:000PM- 3:00:00:000AM 7:12:09:000PM 12:45:09:000AM 5:12:24 0:21:-24
26/09/2010 NithaV.G Development 7:00:00:000PM- 3:00:00:000AM 12:59:59:000AM 3:15:16:000AM 5:12:24 0:21:-24
The same row appear several times.Please help me to select one row only one times.By using 'distinct' it wouldnt become correct..pls help
|
|
|
|
|
Use dateparts to remove the time component of the fields with time values.
You can also do a double convert > varchar using a formater convert(varchar(20),date,103), then convert the result back to datetime format and use that in the report
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Is there any way to link two server other than using OPENQUERY.
|
|
|
|
|
Hi All,
I have a stored proceudure which has dynamic sql in it. This stored procedure has be accessed in a crystal report. Crystal report expert is not showing the Stored Procedures columns. Please anybody advice me how to show the columns of a stored procedure which uses the Dynamic SQL.
Thanks in advance.
Thanks & Regards,
Md. Abdul Aleem
NIIT technologies
|
|
|
|
|
I think you will find the MS discovery will also not get and fields either. I'm not sure (never read up on it) just what magic they use to get the columns but it cannot work with dynamic sql. This seems perfectly reasonable to me as dynamic sql allows you to change the column names - 1 dead report.
Usually dynamic sql indicates a change of underlying object, database, server, table or column structure. Unless it is columns then just dummy up a proc for design purposes.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Graph is map having rooms, house, roads etc.(i.e edges and nodes to find shortest path).
|
|
|
|
|
The answer to this is, as always, it depends. It depends on the quantity of data, the portability required, the type of data, the type of application and possibly a few others.
As a starter I would consider XML (XAML is for markup) only for minimal data that is only relevant to the current user on the current machine.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
All,
I have a slightly complicated issue, I have a Sql 2005 DB which is like 20GB right now, It has different tables related like Projects->Facilities->Locations->Pictures
What I am looking for is the size occupied by an individual project,
Lets say Projects Table has the following
1 Sample Project One
2 Sample Project Two
Facilities has the following
1 1(ProjectId) Facility One
2 1(ProjectId) Facility Two
3 2(ProjectId) Facility Three
and Locations and pictures are related similarly using FacilityId and LocationId
Now I need the data occupied by the entire Project One including the data related to Project One in all other tables.
Hope this is clear,
I welcome any suggestions,
Thanks in advance
|
|
|
|
|
Never having addressed this requirement this is a guess only.
I would take a look at the properties in SSMS, I'm sure the tables have size and rowcount in their properties, this means it is stored in a sys table somewhere. It now becomes a search and mathematics problem. Good Luck
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Can you help me in doing a query in sql that selects for example products that are registered on a date that is on the last week of month, for each month in a specific year?
Thank you
|
|
|
|
|
gertag - read the bloody guidelines, you know the horrible yellow sticky messages at the top of the screen.
Use datepart and datediff to identify the last 7 days of the month and use those dates to filter your product registration.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Good Day,
I wonder if it is possible to joins two columns from two tables (ie column 1 from table A and column 2 from table B) into one column.
Here are my tables (note that the columns from both the tables have the same names)
TableA
----------------------
|Column1 | Column2 |
----------------------
| aaaa | 12345 |
----------------------
| bbbp | 12245 |
----------------------
| ccc | 12245 |
----------------------
TableB
----------------------
|Column1 | Column2 |
----------------------
| asd | 12245 |
----------------------
| bbb | 12245 |
----------------------
| ddd | 12245 |
----------------------
The first part of my SQL statement combines the two columns of each table into one column in each table, thus
TableA
------------------
|Column3 |
------------------
| aaa : 12345 |
------------------
| bbbp : 12245 |
------------------
| ccc : 12245 |
------------------
TableB
------------------
|Column4 |
------------------
| asd : 12245 |
------------------
| bbb : 12245 |
------------------
| ddd : 12245 |
------------------
Now, what I want to do is to combine these two columns into one column.
The SQL statement below gives me the following result
Result
------------------------------
| Column 1 | Column2 |
------------------------------
| bbbp : 12245 | asd : 12245 |
------------------------------
| bbbp : 12245 | bbb : 12245 |
------------------------------
| bbbp : 12245 | ddd : 12245 |
------------------------------
| ccc: 12245 | asd : 12245 |
------------------------------
| ccc: 12245 | bbb : 12245 |
------------------------------
| ccc: 12245 | ddd : 12245 |
------------------------------
What I want is this :
----------------
| Column1 |
----------------
| bbbp : 12245 |
----------------
| ccc: 12245 |
----------------
| asd : 12245 |
----------------
| bbb : 12245 |
----------------
| ddd : 12245 |
----------------
Here is my SQL statement
SELECT TableA.Column1 + ' : ' + TableA.Column1 AS Column3, TableB.Column1 + ' : ' + TableB.Column2 AS Column4
FROM TableA FULL OUTER JOIN
TableB ON TableA.Column1 = TableB.Column1
WHERE (TableA.Column1 IN
(SELECT Column1
FROM TableA
WHERE (Column2 = '12245'))) AND (TableB.Column1 IN
(SELECT Column1
FROM TableB
WHERE (Column2 = '12245')))
I've tried all kinds of joins; left outer, right outer, inner, cross. All with the same results.
I would really appreciate your help, as this is kinda urgent!
Thanx a lot!
Rossouw
P.S I am using SQL Server 2005
|
|
|
|
|