SQL Select Upcoming Birthdays

I'm trying to write a stored procedure to select employees who have birthdays that are upcoming. SELECT * FROM Employees WHERE Birthday > @Today AND Birthday < @Today + @NumDays This will not work...

Calculating number of full months between two dates in SQL

I need to calculate the number of FULL month in SQL, i.e. 2009-04-16 to 2009-05-15 => 0 full month 2009-04-16 to 2009-05-16 => 1 full month 2009-04-16 to 2009-06-16 => 2 full months I tried to...

stored procedure returning value

using this code : ALTER PROCEDURE [dbo].[get](@i int) AS BEGIN declare @ADate datetime select @ADate = ADate from table where [email protected] and DateDiff(day ,getDate(), aDate ) > 0 and aDate is not...

SQL Server significant digits

I have a variable that I want to return a max of 5 to the left of the decimal and always 3 to the right CONVERT(VARCHAR(14),CONVERT(DECIMAL(8,3), ...

Is the error that I am using a cursor or is there an issue with the rest of this script?

This code works fine in SQL 2005 but appears to miss a random number of records from the end of the select in SQL 2008 or SQL 2008R2. I use this code to backup databases on my production servers....

How to count number of records per day?

I have a table in a with the following structure: CustID --- DateAdded --- 396 2012-02-09 396 2012-02-09 396 2012-02-08 396 2012-02-07 396 2012-02-07 396 ...

CURRENT_TIMESTAMP in milliseconds

Is there any way to get milliseconds out of a timestamp in MySql or PostgreSql (or others just out of curiosity)? SELECT CURRENT_TIMESTAMP --> 2012-03-08 20:12:06.032572 Is there anything like...

SQL Server 2008 CASE Logic in SELECT statement

Hello again SQL Server 2008 gurus. I need to apply the following rules to the setting of a worker's start and end times for their work day (hourly employees) in a SELECT statement. I apologize in...

SQL STATE 37000 [Microsoft][ODBC Microsoft Access Driver] Syntax Error or Access Violation

Good day! I get this error: SQL STATE 37000 [Microsoft][ODBC Microsoft Access Driver] Syntax Error or Access Violation, when trying to run an embedded SQL statement on Powerscript. I am using...

Counting orders per hour in a month defined by WHERE clause

I'm hoping to count orders per hour for every day in the last month. I have this WHERE clause from another report (1), which determines the correct month 'last month' from the point it is run. I'd...

Get date difference in VB.NET

I want to get the difference between two dates chosen by two date time pickers in years, months & days in separate text boxes. I've tried: txtyrs.text =...

DateDiff to output hours and minutes

my code gives TOTAL HOURS in hours, but i am trying to output something like TotalHours 8:36 where 8 represents hour part and 36 represents minutes part mean totalHours a person has worked in...

Creating a Calendar in Access 2010

I have been desperately trying to find a way to make a calendar in Access. I know it can be done, as I've seen wonderful examples, but I don't know how. (Also, my VB knowledge is...

Conversion failed when converting date and/or time from character string -

I have below query: declare @migdate as varchar(10) set @migdate = 20140501 SELECT ID, (CASE WHEN a.HD ='abc' THEN DATEADD(YEAR,1,a.LTST_DATE) ELSE CASE WHEN...

SQL - Incorrect syntax near the keyword 'AND'

I'm trying to run an insert statement using three sets of data collected by using a union all. If I run the select statements they work correctly, but if I run the insert statement I get the...

How to calculate ages in BigQuery?

I have two TIMESTAMP columns in my table: customer_birthday and purchase_date. I want to create a query to show the number of purchases by customer age, to create a chart. But how do I calculate...

Why do I get "A cursor with the name already exists"?

I have this trigger: CREATE TRIGGER CHECKINGMAXQTYDAYSVACANCY ON TDINCI AFTER INSERT AS DECLARE @incidentCode int, @dateStart datetime, @dateEnd datetime, @daysAccumulated...

SQL Azure raise 40197 error (level 20, state 4, code 9002)

I have a table in a SQL Azure DB (s1, 250Gb limit) with 47.000.000 records (total 3.5Gb). I tried to add a new calculated column, but after 1 hour of script execution, I get: The service has...

How to get the number of business days using mysql

I have to find the number of business days using mysql.I am using this query but this is not giving me the correct result SELECT ((DATEDIFF('2015-05-31', '2015-05-01')) -((WEEK('2015-05-31') -...

Crazy MS SQL Server JDBC driver at datetime field or time zone issue?

During debugging I end with simple example: select convert(datetime, '2015-04-15 03:30:00') as ts go Apr 15 2015 03:30AM (1 row affected) select convert(int, datediff(second, '1970-01-01...

MySQL: Table alias doesn't work

I want to rewrite this query so it would be working with table and column alias, but I can't get it working. After some research I found that we cannot use table alias in WHERE clause, I tried to...

To get the previous month's last date till last second

I want to get last month's last date (whether 30 or 31) and time till last second, whenever the query is executed. Eg. 11/30/2015 11:59:59 PM So I have a query like SELECT DATEADD(ss,...

Using GROUP BY with FIRST_VALUE and LAST_VALUE

I'm working with some data that is currently stored in 1 minute intervals that looks like this: CREATE TABLE #MinuteData ( [Id] INT , [MinuteBar] DATETIME , [Open] NUMERIC(12,...

Conditional Expression in SSRS

I wrote this expression and getting errors, not sure why. I am trying to get if Fields!Started.Value is in between 3-6 days old, and Fields!NumSuccess.Value = 4, then I should get "Yellow". If...

working days between two dates in ssis

I need help to calculate working days between 2 dates in ssis. Source is excel and destination is oracle. Sample date :I have 2 date fields from excel source some times date1 will greater than...

Case When syntax expression in jooq

I am trying to reproduce this MySQL query in jooq select case when year(d.date) - p.birth_year < 5 then '<5' else '5+' end as age from partners p join departure d on d.id =...

Group Rows By Date Range

I'd like to know how many rows, for a user, exist within a certain number of seconds (like 10). So, given this data: UserId CreatedDate 4.........2017-01-11 01:40:19:077 4.........2017-01-11...

SQL code error mismatched input 'from' expecting

Hi below is my SQL code and it gives me error and I do not know why. If anyone can help. select time_dif, count(time_dif) as count from ( select datediff(so_so_close_time,date_closed) as...

date_trunc month in SQL Server

I want to extract the "month" from the date_contact column. I tried select dateadd(mm, datediff(mm,0, date_contact), 0) from cohort and select cast(date_contact As Date). I received result that is...

SQL DATEADD Function for 7 days after the end of the last quarter

MS SQL Server: I'm trying to get 7 days after the end of the last quarter... Here's what I have so far. DATEADD(D, 0, DATEDIFF(D, 0, DATEADD(s,-1,DATEADD(q, 1, DATEADD(q, DATEDIFF(q, 0, GETDATE())...