I have a table with some data and I was trying to Replace the Column with Row. The above Query gives me the result in one single row data. But I want the Result in below format I have tried the Pivot Operator using Derived Column but got confused during implementation. Please help to get the correct query. An…
Tag: sql-server
SQL creating overview for data that does not exist
I need a script that will give me a total sum of amounts per sort for the past 3 days and upcoming week. I have made a script (link to dbfiddle.uk) that will sum the amount of the grouped date and sort types. However I am unclear on how to move forward at this point. I want the past 3
SQL group by date of DateTime and select first and last value
I am grouping by the date part of a DateTime column using the CONVERT function selecting the MAX and MIN price value for that date. I would like to include the first and last price values for the …
SQL Key Value Pair Query
I have two tables: Product Table ID (PK), Description, CategoryID, SegmentID, TypeID, SubTypeID, etc. Attribute Table ID (PK), ProductID (FK), Key, Value And I would like to query these two …
Repeat insert statement without GO
Is there a “nicer” way to achieve the same results as this SQL query: Which is to insert 300 default all NULL (except PK Id col) new lines into an empty table? It seems to take a while! Also, the value 300 could be completely variable e.g. something like but that obviously doesn’t work: Answ…
SQL Server insert EXCEPT without selecting from a table
I want to insert some people into a user table using: I don’t want those entries entered if they already exist (there is an ID column, but the uniqueness here should be dictated by a composite of those two columns. If I was selecting these values from a table I could use (I think): So how can I do this
Get first and last 6 months in year with timestamp in SQL [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 need to create first and last 6 months in a year, not considering from current date: I use…
SQL how to get latest date and update every time it occurs (not using MAX)
I’m trying to get the latest date of starting event before it occurs again. Data I have: What I want to make: I want to create another column with the latest start time and record it, then update it whenever it happens, and keep that value from there until start appears again. What I tried: This didn…
Update column based on existence in another column
I have two SQL tables. I am trying to conditionally update the second based on detecting existence of a value, URL in the this example, in the first. The first table, Applications, has the following data: In the second table, Modernize, I have the following data: The expected result would be if a URL is detec…
SQL Server – convert date to weekday and count each instance of weekday in second column
Wondering how to select from a table: I’d like to get a result table of two columns: weekday and the number of purchases of each weekday. So far, I have something like this: But this returns two Thursday rows and two weekend rows, because they are different weeks. How can I get it to only return 1 row f…