The intent of the following algorithm is to extract certain set of fields from a key (in this example, extract first 2 fields), and it works. The fields are delimited by a colon: Result: Field-1:Field-2 Microsoft document says that the first parameter is an expression, but I think what they mean by that in the context of CHARINDEX is, that
Tag: sql-server-2014
Using select distinct with sum
I am not sure if what I want can be done but basically, I have a homework where I am supposed to come up with sql statements to filter through a database of a made up TCM company in any way. I wanted …
How to add “or” in SQL select query?
I am creating a report to get customer wise incoming payment in a particular period. Payment can be received through Cheques, Direct Bank Transfers, Cash. This payments saved in the database in a …
How to insert new rows based on values in other columns in sql server?
I have a dataset like below: Id A14_Comment A15_Comment A16_Comment 1 Comment1 null null 2 Comment2 Comment3 Comment4 3 null Comment5 …
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 @…
Filter and keep most recent duplicate
Please help me with this one, I’m stuck and cant figure out how to write my Query. I’m working with SQL Server 2014. Table A (approx 65k ROWS) CEID = primary key CEID State Checksum 1 …
Is a non-clustered index implicitly created for each foreign key in a table?
If I have a table like so: CREATE TABLE MyTable ( Id INT PRIMARY KEY IDENTITY(1, 1), FooId INT NOT NULL FOREIGN KEY REFERENCES Foo(Id), Data NVARCHAR(10) NOT NULL ); The following …
Why CAST from Date time to varchar works in one Environment but not the other?
For this questions, we have two environments, Dev and Prod with both running sql2014 with dev being a developers version and prod an enterprise version. Dev is running the below version(s) Prod is …
SQL Server 2014 – Show record even if zero (General Ledger reporting)
I am creating a General Ledger report for the finance team. I have a list of all transactions by calendar Month. Of course some GL codes are not used every month for whatever reason. I do have another …
Query to concatenate rows based on data from multiple rows
I’m trying to print out xml results with a query in SQL Server 2014. The query is supposed return data from a date range, and return a concatenated list of player names and player times. The …