I have a set of strings that has datetime values and I would like to extract them. I am not sure if this is even possible using T-SQL. Expected Results: Answer For this dataset, string functions should do it: The idea is to count backwards from the end of the string, and capture the 14 characters that preced the extension
Tag: tsql
How to update row if exist and meet more than one condition and insert it otherwise in SQL Server
I’m trying to perform the below code which I have found it in a thread here The problem is that I need to do the same thing but with the SQL Server query. My main thought here is that if the new read has the same BoxNo and the same SSCC and the same StyleBarcode, then the value in Qty
Using PIVOT to get SELECT into one column, not row
I am trying to make a select, which would show the result into ONE column, not row. I tried using PIVOT, but I am not successful at all. Result of my select: I want to have it like this: Answer You can use cross apply to obtain a single column: results: or, if you prefer having a separate column for
Trigger for automatically updating email field?
I am trying to create a trigger which fires when a new row is inserted into my StudentInformation table without the Email field specified. The trigger should fire and update the email field with …
How to calculate the difference in revenue for 2 specific periods from data in a single table?
I am using SQL Server 2014 and I have the following T-SQL query which is supposed to calculate the difference in total revenue based on 2 specific periods. The data to perform the computation come …
Mark existing rows as duplicates when selecting with left join in T-SQL
I am trying to do a LEFT JOIN to merge a table and view and the right table has duplicate items(usernames). I want to keep them but add another column to mark them as isDuplicate=’TRUE’. I wanted to use CASE WHEN EXISTS but can’t get it to work correctly, it produces wrong results: Ideally I would like to not mark
Getting different results from LIKE query and stored procedure for (starts and ends with) search
I am trying to implement a stored procedure that gets the two parameters @startsWith and @endsWith and constructs this query string: @startswith + ‘%’ + @endsWith To search for entries of a single …
RECURSIVE QUERY – PARENT/CHILD
Say I have a table like so: id Parentid childid ——————————– 01 null 02 02 01 03 03 02 04 …
How can I make this code work on SQL Server
I was wondering why my SQL code isn’t working properly on SQL Server while when I upload it on phpmyadmin it works perfectly. Is it some difference between those SQL’s? Is someone able to make this code working well on SQL Server? I’ve posted only part of database but with your help I’ll get done the rest. Answer As a
Use smaller than on like clause
I have some number like These numbers are only an example I have a lot of 14… a lot of 15… etc. Now in WHERE clause of a stored procedure, I want to exclude all numbers who start with 15 or less so I can do something like: Is there a way to change this and use something like TestColumn