I am revisiting MS SQL after a few years, so apologies for a basic question! I am performing some address data cleansing, to expand abbreviations like DR into ‘DRIVE’ RD into ‘ROAD’ etc to help with identifying duplicate addresses. I am exploring ways to optimise my query by taking my …
Tag: sql-server
How to convert date format in SQL Query Results?
I want to display Date fields in SQL Query Results as DD-MM-YYYY Format. In table it is vice versa. When I try with below query it does not works. SQL Query Link: (Tables can be retrieved by clicking …
Query to select between two dates without year
I am trying to update certain fields for employees whose date of joining falls in between 10 Jun and 31 Dec, irrespective of the year. I am trying using ‘Between’ Operator but it requires year to be included in the dates. Is there a way to generalise it in order to consider Day and Month excluding…
Displaying student absent dates
Here is the table I want to display: Now I want to search by from to date and want absent date. How can I achieve this? I tried below code: i want date for which student absend Answer Basically what you need is list of possible dates between From and To
Group by values that are each multiple of number
This is the table t. I want to group it every time the TotalQty >= 5n (let n = group). i.e. once the TotalQty >= 5n I want to sum together the qty from n-1 to n. With this query I can get pretty close but I doesn’t consider the the previous “valid” TotalQty + 5 — How do I
select max, min row for each group without subquery with case of same [closed]
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 2 years ago. Improve this question I’m trying to avoid sub queries because it generally takes longer to run. Came across …
SQL Union as Subquery to create Date Ranges from Start Date
I have three tabels, each of them has a date column (the date column is an INT field and needs to stay that way). I need a UNION accross all three tables so that I get the list of unique dates in accending order like this: Then I need to add a column to the result of the query where
Multiple SUM in one query with multiple where
I’m trying to write a SQL query that produces a table with summarized values for each year and month. I have a table that looks something like this: And another table that looks like this: I want to have a query that returns the sum for each month like this: Explanation of the output: Year and Month are…
How can i mention AM/PM while inserting time value into a table in sql server?
I am trying to insert values in time and column of table(doughnut_ratings) separately, but it is giving following syntax error: Msg 241, Level 16, State 1, Line 65 Conversion failed when converting date and/or time from character string. I am writing the following query, please suggest Answer The problem isn&…
How to use DISTINCT and SUM in a same SQL query on MS SQL Express
I have a situation where I need to get DISTINCT values from column “note” and then get the SUM of “price” for above records. I tried with different queries but none of them are working fine. SELECT …