Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 months ago.
Improve this question
Can someone tell me what I am possibly doing wrong in this query? I am getting the error message
Conversion failed when converting date and/or time from character
string
So I think it does not like the DATEADD part, but I have used that before (not as part of a join) and it worked fine. I can't figure out any other way to filter out for just the past month though. Thank you!
SELECT ----
FROM dbo.LocationRevenues AS lr
INNER JOIN dbo.Subscriptions AS sub
ON (lr.order_number_id = sub._order_number_id_)
WHERE sub._starts_at_ BETWEEN DATEADD(MONTH, -1, GETDATE()) AND GETDATE()
AND lr.subchannel_code = 'Channel'
AND lr.location_name != 'LocationA';
This script will find the problem for you.
SELECT sub.starts_at_
FROM Subscriptions sub
WHERE ISDATE(sub.starts_at_) = 0
Add another column such as the PK to the select list to help track down the actual row.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 months ago.
Improve this question
I have to take over old colleague's code and trying to understand this one SQL statement like below:
SELECT * FROM my_table WHERE date_key = '{0}'
Column date_keycontains int values such as 20220712, 20220120, etc.
The first guess is that SELECT statement filters for rows with 0 value in column date_key. However, when running that line of code, I receive this error :
SQL Error [100038] [22018]: Numeric value '{0}' is not recognized
What exactly does that line of code do?
That looks like a placeholder, replaced with an actual value in code when calling the query.
See similar What is {0},{1},{2},{3} in the SQL query
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Trying to select data only between a range.
select ITM_NBR,
TOT_IVO_ITM_QTY,
Count(*)
FROM dataset
WHERE
bus_dt BETWEEN '2-14-2020' AND '2-15-2021'
Failed conversion to numeric value. Tried without single ticks and it returned zero rows which makes me believe that the column is stored as a VARCHAR. Tried Casting the bus_dt column into a date format.
CAST(bus_dt AS DATE FORMAT 'mm/dd/yyyy') BETWEEN 2/14/2020 AND 2/15/2021
Again failed conversion.
I feel as if I’ve tried every combination and can’t get anything to work of casting and putting the date values in yyyy-mm-dd, mm/dd/yyyy, etc. formats.
And also when I HELP VIEW to see the column type I get “?”.
Kind of at a loss right now.
After I thought I tried everything I figured it out....
I was not formatting my date literals correctly .... faceplam
DATE'yyyy-mm-dd'....
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a lot of issues using the datediff function in SQL Server.
I have two tables that I want to join based on the time gap between observations; the tables contain arrival times of shipments as follows yyyy-mm-dd hh:mm:ss.
I found a different question of which the answer will (hopefully) help me with the join bit. The code provided by said example states the following, and this is where the struggles begin.
Abs(DateDiff("d", pi.Product_Interest_Date, l.Lead_Date)) AS Date_Gap
Source: Join two tables on the same date or closest date (before or after)
However, I need to find the date gap between values based on the full date, so from year to seconds. Am I correct in understanding that the datediff function only accepts one level (i.e. only day or minute), or am I doing something wrong?
If the former is the case, is there an easy way to do what I want to do?
First, the syntax in SQL Server for days is:
abs(DateDiff(day, pi.Product_Interest_Date, l.Lead_Date)) AS Date_Gap
The syntax that you are using is MS Access syntax.
SQL Server does not have an interval type. You can get the difference in seconds and then convert to another unit. For instance, decimal days is:
abs(DateDiff(day, pi.Product_Interest_Date, l.Lead_Date)) / (24.0 * 60 * 60) AS Date_Gap
You don't provide sample data and desired results that describes the exact results you want, but this should put you on the right track. If this doesn't fully answer your question, then you should ask a new question with sample data, desired results, and a clear explanation of the logic.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I Couldn't find the value that has 'r' in the third position using LIKE operation in SQL.
could anyone help me, please?
I think it would be better to write something like this.
SELECT <column>, FROM <table> WHERE <condition> LIKE "__r%";
EDIT:
This is tested and functional for SQL Server and Oracle DBMSs.
SELECT * FROM <table> WHERE substring(<column>,3,1) = 'r'
Try this. This is using SQL Server which will yield the result you are looking for.
You want to get the r from 'scr' with position 3
Try this
SELECT * FROM Customers
WHERE CustomerName LIKE '__r%';
position is count of _.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Can someone help in coding a Access SQL statement/Query where I have a table with columns as shown with Ident No not primary
Ident_No-----Data1-----Data2-----Data3-----Data4-----Data5-----Data6
1----------------abc--------def---------null---------null--------null--------null
1----------------null--------null---------ghi----------jkl----------null--------null
1----------------null--------null---------null---------null--------mno--------pqr
Looking for result as shown below in the query result or a new table.
Ident_No-----Data1-----Data2-----Data3-----Data4-----Data5-----Data6
1----------------abc--------def---------ghi---------jkl--------mno--------pqr
Please Help Thanks in advance
You need to use group by and get the MAX() value for each column like
select `Ident_No`, max(`Data1`), max(`Data2`),
max(`Data3`), max(`Data4`), max(`Data5`), max(`Data6`)
from tbl9999
group by Ident_No
See live here http://rextester.com/CIHY78216