Skip to content

Tag: sql-server

Replace row with Column Data in Sql Server

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…

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 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…

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…