I am trying to insert large amount of data from one table from PROD DB to table in Archive DB. Tables are with the identical schema and archive table is with drooped indexes and “Identity insert on”. …
Tag: sql-server
Combine date ranges for rows with same value
Data Looks Like Below – my desired output is that when the next entry in the day is the same value those times are combined to get a total time. Once a value changes, take the date of the first entry (…
How do I duplicate a column in a SQL Table?
I am using SQL Server 2014 and I have a table named Table1. Assuming I want to duplicate a column named SubCategory into a new column called SubCategory2 (with the same values as in column SubCategory)…
select rows with events related with another events in the same query column
I need to select rows with EventTypeID = 19 which does not have related EventtypeID = 21 LoggedOn exactly 4 minutes earlier for the same EmployeeID. Here’s the query bellow and some raw output: …
Store a list of numbers returned by a query into a variable
I’d like to store the Ids returned by a query like so into a variable: SELECT FooId FROM Bar; — FooId is of type int So that I may later say something like: DELETE FROM Foo WHERE Id IN @…
SQL Server query to group records and insert in other tables
I am using SQL Server database which has tables x, y and mapping table xy. I have a table X with x_id, date, text and receiver id and mapping table xy with x_id and y_id. I need a script to generate …
DELETE and NOT IN query performance
I have following table structure: Users UserId (primary key) UserName SomeItems SomeId(FK to Users.UserId) SomeItemId (primary key) Name Other stuff… SomeOtherItems SomeId2 (FK to Users.UserId)…
Repeat column values in existing rows
Have a table with the following structure: Rownumber ID Type Category Value 1 100 1-Purchase Order Address Cedar Rd 2 City Beachwood 3 …
How to get only Capital letters from given value
I have a table it contains ID, Description and code columns. I need to fill code column using description column. Sample Description is “Investigations and Remedial Measures” so my code should be “IRM”. Note: Is there any words like “and/for/to/in” avoid it Answer This codeā¦
Select first 10 rows of a column in a table
Can you please let me know how to select first 10 rows for every cusip in the below table SELECT [dt_dim_id], [cusip_num], sr.[product_dim_id], [acct_dim_id], […