I need to extract the first argument: “PATHTOPACKAGE” from the string below: which is a column stored at SQL Server msdb.sysjobsteps.command Is there a way to do it by using Regex or Spliting it by blank spaces? Answer Based on the one example we have, a couple of CHARINDEXs a little bit of simple…
Tag: sql-server
SQL Group with time
Sample table id dept ctime 100 A 09:15:12.0000000 200 B 08:00:00.0000000 300 A 09:00:00.0000000 400 B 08:50:00.0000000 expect to see countid dept xtime 2 A …
How to count SQL based on a DateTime and an other variable?
I have a SQL table with failed testresults: This table is telling me that the test has failed, but I want to know if it is the first, second or third test. In the end I would like to do it with a logo where a x stands for a failed test, and a X for the concerned test, like
Replace Database WIth Copy Of Other Database
As part of our testing process, I’m trying to automate the following: Drop DatabaseB. Create a backup of DatabaseA Recreate DatabaseB from the backup of DatabaseA I had hoped something like this would work RESTORE DATABASE DatabaseB FROM DISK = ‘c:tempDatabaseA.bak’ WITH REPLACE, but that tu…
Recursivly call on a lagged value in the same column, Or Have two interdependent columns
The first query does not run because I have a SUM() inside a LAG() which is just illegal but I’ve included it just to conceptualize the idea. Or Now I should mention there is are two null columns, result and CumRes, in “ready_set” which is why the second query even runs. Here is the exact id…
SQL Syntax – Section in MERGE Statement
It’s been a while since I’ve worked in a T-SQL environment. I previously worked for Google, and, of course, they had their own special flavor of SQL. Now that I’m back, I’m reading back up on my T-SQL features. I understand the MERGE statement (at least, I think I do!), but I was looki…
Counting values within the same row in SQL Server
My SQL Server problem is as follows: let’s say we have clients and we wish to rate them based on 4 categories (Score_1…Score_4) on a scale of 0 to 2. I have a table presented below: What I want my code to do is count the number of 0, 1, and 2 values each of my clients recieved. The result
Get All dates for given month and year and join in same table sql
Currently I have data in below format in my table How can I get date wise for every month and year like below Answer First, personally, I would create a Calendar Table. You can quickly create a simple one with the below: Then is just a trivial case of joining your table to the calendar table:
Rows with duplicate column values
I am pretty sure there are rows with duplicate column values in the table: SELECT TenancyReferralKey, FromDate, ToDate, ToDate_Value, ReferralID, ReferralFor, …
How to convert month to week to this query
;With CTE_Mem as ( Select m.PeopleID , m.Operator, m.LocationName, sum(case when M.ActiveStart < DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 1, 0) AND M.ActiveEnd > DATEADD(MONTH, …