I’m trying to write a query to select all orphan records that are in a child table, but only when orphaned records are the only items in the table. I have two separate databases from separate systems,…
Tag: tsql
Sum with SQL depending on the value of a column
I have 3 columns : year, price, and day_type. year day_type price 2016 0 10 2016 1 20 2016 2 5 2017 0 14 2017 1 6 2017 2 3 I want to keep only the lines where day_type = 1 or 2, but add to these …
How do I select birthdays in the next 30 Days
I have a table with birthdates and I want to select all the birthdays that will come in the next 30 days. The situation is, that all the birthdays are written in the form off 1999-09-15 which means that even if I tried selecting the next 30 days, the birthdays wouldn’t show up because the year is 1999. I am
T-SQL Query Column based on filtered condition
I could do this rather easily in Python (or any other language), but I’m trying to see if this is possible with pure T-sql I have two tables: Table A has a bunch of general data and timestamps with each row Table B is considered metadata So the general data is referenced to a “RunNo”. The timestamp in table B
Converting string to integer and then converting back to string
I have some update statements like this: UPDATE tmp SET MyVarCharColumn1 = ISNULL(SomeOtherVarCharColumn,0) FROM #myTempTable tmp; Note that MyVarCharColumn1 is of type VarChar() but in real …
STRING_SPLIT in TSQL on MS Server creates list with repeating values. WHY?
I am using 2017 MS SQL Express. The following code creates this erroneous result. Any clues why? SELECT BNAME, LIC_STRING INTO dbo.SEPARATE2 FROM dbo.together CROSS APPLY STRING_SPLIT(LIC_STRING, ‘,’)…
Concat based on sequence number
I’m trying to concat a text field based on a separate field and sequence number. For this example let’s say the fields I have are employee ID, Sequence#, and Comments. The comments field is limited …
Filter msdb.dbo.sysjobsteps.command into seperate columns
I am trying to split the msdb.dbo.sysjobsteps.command column into separate columns to show the following information: folder project dtx package A small sample of my data is below: I have tried to use the substring method, however I cannot seem to get the starting and ending number of the substring. My aim is for the following in a ssms table:
How to merge rows based on date/time
Microsoft SQL Server Management Studio 14.0.17224.0 I have a dataset where users perform tasks for clients. Sometimes tasks can be done at the same time and sometimes not. I need to merge records …
T-SQL query to show only differences between rows
I have a query that outputs the following dataset: I need to find a way to find instance where the unitid column and the stat column do not match. An example would be if unitid = 2, CleanCode = 10 …