Tag Archives: t-sql

Remove Characters in String T-SQL with No Loop Part 2

Okay, expanding on what I did yesterday. I Built a table, called ExclusionList with one field, ExcludedText E.g. Then created a function: You can then use like this: Advertisements

Posted in Programming | Tagged , , , , | Leave a comment

Remove Characters in String T-SQL with No Loop

Ok, I’ve seen many ways to do this using loops, but nothing in plain T-SQL Let’s say we have a string that may contain illegal characters, in my case it was project identifiers that needed to be used as file … Continue reading

Posted in Programming | Tagged , , , , , , | Leave a comment

Insert or Update Record in SQL Server Depending on Whether it Already Exists.

This is a simple example on how you can use T-SQL to Update a record if it already exists, or add a new record if it doesn’t. This example uses a table STOCK_ITEMS, with two fields ITEM_ID and ITEM_VALUE. If … Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

Select Top and Bottom Record using T-SQL

The example below shows how to select the top and bottom records based on a particular field. In this case we have a WORK_ORDER table and we want the rows with the maximum and minimum TARGET_DATE.  The idea is to … Continue reading

Posted in Programming | Tagged , , | Leave a comment

Passing Database and Table names as Variables in SQL Server

I often want to apply the same SQL to one or more tables in one or more databases.  This requires passing the  database and table as a variable (or copying and pasting the code multiple times). Below are three ways … Continue reading

Posted in Programming | Tagged , , , | 2 Comments