|
This will be a permissions issue. Your executing sp doors not have permission to use master system procedures
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I have employees table with date_of_join field
and I have employee_leaves table with the following fields:
employee_id
leave_from
leave_to
total_days
the employee joined on 15 Feb 2011
I want to have a query showing the cound of leaves for every employee years based on his date_of_join
for example, if the employee joined on 15 Feb 2011 then the result will be like this:
Feb 2011 to feb 2012 ---- totals days: 21
Feb 2012 to feb 2013 ---- totals days: 26
Feb 2013 to feb 2014 ---- totals days: 8
where Feb to feb is the employee year so it's from 15 Feb to 14 Feb every year
can anyone help please?
Technology News @ www.JassimRahma.com
|
|
|
|
|
What have you tried?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am not able to get it...
I tried:
SELECT employee_leaves.leave_from, employee_leaves.leave_to FROM employee_leaves
JOIN leave_category ON leave_category.leave_category_id = employee_leaves.leave_category
GROUP BY YEAR(employee_leaves.leave_from);
but this will just group by cal;ander year not employee year
Technology News @ www.JassimRahma.com
|
|
|
|
|
You can only group on fields that are present within the query (or calculations based on one of those fields). You can get get the start of the contract by looking for a MIN-entry. Add 365 days to that fact, that's your range.
That does not account for leap-years of course.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Better add 1 year and not 365 day...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Does it account for me joining the company on the 29th februari?
Edge case from Hell
If you can't read my code, try converting it here[^]
modified 10-Sep-14 16:14pm.
|
|
|
|
|
That does not matter to SQL - it has the requested knowledge to handle the 29th of February...
In fact if you are working with 365 days you have to know when to add 365 or 366 to land on the right date - otherwise you will always get 28 of February.
If you work with year you will move between 28 and 29 as it proper to the year...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Hi,
I want to ask how the CREATE EVENT in MySQL works? does it use the operating system event schedule (Wndows Task Scheduler, CRON, etc) or MySQL has its own event scheduler?
and can you rely on MySQL CREATE EVENT or it's better to have a process in Windows task Scheduler?
Technology News @ www.JassimRahma.com
|
|
|
|
|
Jassim Rahma wrote: and can you rely on MySQL ..well, if they say they implement a timer, you can rely on it that it works as described in the manual
Jassim Rahma wrote: or it's better to have a process in Windows task Scheduler That depends on your needs. If you are modifying data at a specified interval, then it might best be done in the database. If it doesn't need the database, then it would be better of in the task scheduler. Another big difference (does not make one better than the other) is how they are managed, and the person who has those permissions. For the task-scheduler that's the local Windows-admin, for MySQL it is probably the MySQL SA.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi guys
I have database hr has table Employee this table has field EmployeeName
EmployeeName nvarchar(50)
when i write in query analyzer :
select ^ from Employee where EmployeeName='احمد'
not give me any result
but when i write
select * from Employee where EmployeeName=N'احمد'
it give me result
meaning it support arabic
but i have stored procedure not accept arabic and i dont know how to handel it to accept search by EmployeeName
CREATE Procedure sp_EmployeeSelect
@EmployeeName nvarchar(50)
AS
Declare @SQLQuery as nvarchar(2000)
SET @SQLQuery ='SELECT * from Employee Where (1=1)'
If @EmployeeName <>''
Set @SQLQuery = @SQLQuery + ' AND (EmployeeName LIKE ''%'+@EmployeeName +'%'') '
Exec (@SQLQuery)
what is the proplem in this stored procedure and how to solve it
please help me
|
|
|
|
|
Why don't you apply the solution you found in query analyzer
select * from Employee where EmployeeName=N'احمد'
in the stored procedure? I.e.
Set @SQLQuery = @SQLQuery + ' AND (EmployeeName LIKE N''%'+@EmployeeName +'%'') '
|
|
|
|
|
I'm repeating myself here:
Don't use string concatenation to build a dynamic SQL query. Your code will be susceptible to SQL Injection[^].
If you really need to use a dynamic query, use sp_executesql [^] to execute it:
CREATE Procedure sp_EmployeeSelect
@EmployeeName nvarchar(50)
AS
Declare @SQLQuery as nvarchar(2000)
SET @SQLQuery = N'SELECT * from Employee Where (1=1)'
If @EmployeeName <> ''
Set @SQLQuery = @SQLQuery + N' AND (EmployeeName LIKE N''%'' + @EmployeeName + N''%'')'
Exec sp_executesql @SQLQuery,
N'@EmployeeName nvarchar(50)',
@EmployeeName
However, in this case, as with all of your QA questions, you don't need a dynamic query:
CREATE Procedure sp_EmployeeSelect
@EmployeeName nvarchar(50)
AS
SELECT
*
FROM
Employee
WHERE
@EmployeeName = N''
Or
EmployeeName Like N'%' + @EmployeeName + N'%'
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello everyone,
Can someone help me select rows between 2 dates en between 2 times.
I need to select all records from 02/09/2014 starting from time 05:00:00 until the next day time until 05:00
If I do it like this then it wont work, no records shows:
SELECT TOP 10000 *
FROM Staging.[dbo].AD
WHERE DATE_CREATED BETWEEN '02/09/2014' and '03/09/2014'
AND Convert(Time,TIME_CREATED) between '05:00:00' AND '05:00:00'
It should be something like this:
Between DATE_CREATED 02/09/2014, TIME_CREATED 05:00:00 and DATE_CREATED 03/09/2014, TIME_CREATED 05:00:00
Kind regards,
Ambertje
|
|
|
|
|
SELECT TOP 10000 *
FROM Staging.[dbo].AD
WHERE DATE_CREATED BETWEEN '02/09/2014 05:00:00' and '03/09/2014 05:00:00'
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Thank you for the reply but this is not working, it's showing me all the records for both days, not the records between 05:00:00 and 05:00:00
|
|
|
|
|
What datatype is time?
I'd recommend putting it in the DATE_CREATED column, where it belongs.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Why are you using nvarchar instead of DateTime ?
|
|
|
|
|
Yes, kinda predictable.
It's a bad idea to do so, and should be fixed. The time you are saving is a culture-specific format, it is a text, something the computer does not calculate with.
A DateTime in a computer is a floating point. The integer-part counts the days passed since the epoch (start of counting of days, often 1/1/1900), the decimal part represents the time, in ticks. They are not two separate facts - and should be modelled as a single field, of the DateTime-datatype. The computer can easily calculate with those.
Breaking the date and time into separate fields is as usefull as using a separate field for the day, month, year, hour, minute and second. If they represent a single atomic fact, than that is how it should be modelled.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It's interesting that the Date type in Oracle while handled as a single entity but is stored internally as seven bytes. One byte each for year, month, day, hour minute, second and fraction of a second.
It's a space waster, but oh so fast to calculate with.
Timestamp on the other hand is stored as a floating point to save space.
|
|
|
|
|
Internally, yes, if the engine expects it. But still no way to model a database.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
If date and time should not be keep separate, why did MS create data formats DATE and TIME?
|
|
|
|
|
Because there are times when you do need to store just a date or just a time. The OP's example just isn't one of them.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|