I have a table CustomerLocation with the following columns : Country Region City I want to create a composite primary key with the 3 columns mentioned above knowing that the Region column is NULLABLE. Answer You can’t. The definition of primary key specifies that only non-NULL values are allowed. This is clearly explained in the documentation: All columns defined within
Tag: tsql
How to get all rows from a SQL table before a change in column string?
I have these 2 tables and their inserts: I have this query to partition them by JobId and order them by JobId and StatusDtTm: I want to fetch only the rows where the Job last finished per job. Basically get all the records per job before it last finished (highlighted in green). I can’t seem to figure out what to
SQL Daily Outstanding Sales, Rolling Aggregate?
With the below test data I am trying to show how many sales have not been actioned by a colleague, an outstanding sale is any record that is still showing as “New”, I have been using the below to …
Using sum with multiple dates but keeping only the latest date
I have a table called Prospect that looks like this and I’m trying to SUM the value so that I have only 1 column for GEORGIA, ALABAMA,TEXAS and the date kept in the date field be the latest date entry. I would like to have a resultset that looks like this This is what I’ve tried, but it is not
SQL Group by date with multiple same results
How to write a statement that groups data by date but shows when data changed for the first time date – when data changed a,b,c – some data and it can be anything This is should be the result. It might have the same data on different dates, but it missing the next day when data stayed the same. It
Update records in SQL by looking up in different table
I am copying data from few tables in SQL server A to B. I have a set of staging tables in B and need to update some of those staging tables based on updated values in final target table in B. Example: Server B: StagingTable1: StagingTable2: After Copying StagingTable1 to TargetTable1 (ID’s get auto polulated and I get new ID’s,
SQL Server query duplicating rows based on inventory locations that have been claused out
My current code is duplicating results per item_id. I am summing the previous three months usage per item in two locations. I do have more locations but I limited it in the WHERE clause. I think the …
Compute a Decreasing Cumulative Sum in SQL Server
What I’m trying to achieve is a cumulative sum on a non-negative column where it decreases by 1 on every row, however the result must also be non-negative. For example, for the following table, summing over the “VALUE” column ordered by the “ID” column: I expect: Answer Your question is not very well described. My best interpretation is that you
Import JSON File into SQL Server Table with nested Arrays
I’m trying to import the Census Block GeoJSON file and unable to get “Coordinates” for each block along with it’s properties. I’m trying to get the ID, BlockGrp, Block.. and it’s associated coordinates. Below is my code, but I’m unable to get the coordinates since it’s in an array. Can anybody guide me on how to make it work? The
How to implement the like and share feature for a social networking website? [closed]
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 want to understand how the like button is actually implemented in a Web App (the database table part). How