Tag Archives: sql server

Populating Windows Forms ComboBox from SQL Server using OLEDB and DataTable

For the database connection, and populating the DataTable see my post: Populating ASP.net DropDownList from SQL Server using OLEDB and DataTable Hopefully you have now connected to your database and populated your DataTable. Now all we need to do is … Continue reading

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

Populating ASP.net DropDownList from SQL Server using OLEDB and DataTable

Firstly we need to ensure that we have referenced System.Data.OleDb in order to connect to the Database. Now the database connection: NB: for connection string help / information this is a great resource http://www.connectionstrings.com/ Now we have our open database … 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

Select a range of records from a dataset in T-SQL

This is a way to filter out a numbered range using T-SQL.  I.e. if you wanted to select the 100th – 110th row from your dataset. Firstly use the OVER statement to add row numbers (as ROW_NUM column) to your … 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

Find Updated Objects in SQL Server

Quickly find SQL Objects that you updated “today”: Clearly if you wanted to change the updated date you could enter a specific date or range.

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

Column Dependencies in SQL Server

Having the need to do a column rename in the DB I wanted to try and find all references to the column to ensure I didn’t miss any. By using the INFORMATION_SCHEMA views in SQL server I used the following … Continue reading

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

Counting Trailing Spaces in SQL Server T-SQL

I recently had an issue with some data grouping in a third party application where data that appeared to be the same, was being grouped separately. E.G. Example Data: AB AB AB BC BC BC BC BC BC DC When … Continue reading

Posted in Programming | Tagged , , , | 3 Comments

SQL Filters with Optional Parameters

Lets say, for example, you have some information on Cars that you want to filter buy either make, model, colour, or any combination of these.  I.e. if you select red cars you will get all makes and models that are … Continue reading

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