I’m struggling on how can I fix, for example, 5 random rows of my table in SQL. But I need to be able to repeatable retrieve the same 5 rows every time I run the code with a given seed. I tried to use But I didn’t get the same sample each time that I run the code. Any idea
Tag: sql-server
How to use SQL IN operator with CASE in select query where clause
I have the above sample T-SQL code and in the IN operator of the where clause I want to use multiple values like IN (1,2,3,4) but also I want to use the CASE operator such that I can pass different values to the IN operator depending on the value of @AreaType parameter, how can I modify the code above to
Function to REPLACE* last previous known value for NULL
I want to fill the NULL values with the last given value for that column. A small sample of the data: In this example, the NULL values should be 1089066 until I reach the next non-NULL value. I tried the answer given in this response, but to no avail. Any help would be appreciated, thank you! EDIT: Sorry, I got
Loop through table and update a specific column
I have the following table: Id Category 1 some thing 2 value This table contains a lot of rows and what I’m trying to do is to update all the Category values to change every first letter to caps. For example, some thing should be Some Thing. At the moment this is what I have: But there are two problems,
Convert rows to columns in SQL Server 2008
We have one table called Licenses. This is what it looks like: CustNum LicenseAddress License ExpiryDate 155 123 Y32CA 12/31/2018 155 998 Y32CB 12/31/2020 155 568 Y32CC 12/31/2022 Here is what I want it to look like: LicAddr1 Lic1 ExpiryDate1 LicAddr2 Lic2 ExpiryDate2 LicAddr3 Lic3 ExpiryDate3 123 Y32CA 12/31/2018 998 Y32CB 12/31/2020 568 Y32CC 12/31/2022 Here is the query I
SQL – How to determine fiscal quarter when quarters are determined by # of days?
I have a situation I’ve never seen before, where a fiscal year started on 2/4/2018 is broken down like this: Q1 – 111 days long (2/4/2018 – 5/26/2018) Q2 – 83 days long (5/27/2018 – 8/18/2018) Q3 – 83 days long (8/19/2018 – 11/10/2018) Q4 – 83 days long (11/11/2018 – 2/2/2019) That is considered FY 2018 The next year,
Finding Active Clients By Date
I’m having trouble writing a recursive function that would count the number of active clients on any given day. Say I have a table like this: Client Start Date End Date 1 1-Jan-22 2 1-Jan-22 3-Jan-22 3 3-Jan-22 4 4-Jan-22 5-Jan-22 5 4-Jan-22 6-Jan-22 6 7-Jan-22 9-Jan-22 I want to return a table that would look like this: Date NumActive
Find groups containing 6 consecutive 1s in one column
I have a table with 2 columns: val with values: 0 or 1 id with unique identifiers How do I to find id with 6 values = 1 in a row. In the example above: id = 9, id = 10. It is desirable not to use loops (cursors or while), but something like sum(…) over(…). Answer You can use
How to correctly join two tables that each have Start Date and Stop Date columns?
This should be easy, maybe even a duplicate, but neither my brain nor my search engine is being very helpful today. My problem is as below: Given two tables that both have: A start date A stop date A property of an employee. Let’s say Desk Number in table A and Team in table B The employee’s unique ID number.
How to exclude data if any record is not matching in any of the column in the another Table
I have Table A and Table B I’m looking to join both the tables with all columns in each table. If any record is not matching then we need to remove all the SK. For 17734 value all the columns from the both tables are matching then I need to get the values for 17734 . For 16601 value only