I have several stored procedures that are almost identical but have some different AND parts inside a WHERE clause. Based on a variable deptname, I want to add additional AND/OR conditions to my already existing WHERE clause. So kind of like IF/CASE WHEN on the part that is different. Think about it as string…
Tag: sql
query mysql to find total value
please help me. imagine the table as bellow and I want to query and show result like this I dont know how to write query to show result like that. I used (date_join) as dates, count(id) and group by date(date_join) and the result not show like that. Answer In MySQL 8.0, you can solve this with aggregation and…
SYNTAX_ERROR: line 1:1: DISTINCT in window function parameters not yet supported
I have a table below : I am writing a code below to get the next timestamp using T5 and then calculate the duration. However for the last record where T5 and T6 are equal I want to fill in the average of the previous durations. However I am getting an error in doing so. What am i doing wrong?
how to pass value from one dataframe to another dataframe?
I have to pass the the C_ID value to where condition in below data frame as parameter. Any suggestions how I can do this ? i should not use subquery concept as data is in millions and multiple tables are there in joins,here i have mentioned sample query. Answer Store sql result into a variable using mkString …
Problems with reserved field name ‘user’ in SAS Proc SQL
How do I select the user column from my table and not select the surprise ‘feature’ SAS added to their SQL syntax: Result: Bonus, the field name in the result table (if you create one) gets a temporary name… ie. something like _TEM001. Answer Use the name literal syntax, ‘<name>&…
query for join two column and get one row per left with column that have array of right table refrenced to left table row
hellow.I have a tablt product like this +——-+——-+ | id | name | +——-+——-+ +——-+——-+ | 1 | shirt | +——-+——-+ color table like below: +——-+——–+ | id …
How do I assign methods to a specific parameter using PIVOT in SQL?
We’re working on producing our data as a relational database/set and as a row-column dataset (so that the users of the data can use which format suits them best). Here’s a simplified table of our data:…
How to validate dates are in the format of YYYYMMDD
I have a date column having thousands of rows in the format of YYYYMMDD. I have to validate that all the rows are in the correct date format. If there is any row off from the desired format or in any means (say null) the row should be returned in the result. I have the following sample data: Since NAN
How to get the actual script of a stored procedure in another server?
I use SQL Server 2017. I have linked a serverdatabase to another my main database. So, if I execute the query below, it works and brings me the correct data: What I want to do is to get the actual script of a stored procedure from the linked database. Assume I have the stored procedure: sp_GetNumbers, then I …
Get the row where the sum of a value matches a condition
I have a table with the columns: date (timestamp) num (integer) Looks like this in CSV: I want different queries to figure out the following: A: The earliest date that the sum of num is >= 1 B: The earliest date that the sum of num is >= 2 In the sample data the output would be A: 2018-02-07 and