Jump to content


Check out our Community Blogs

Barnsite's Blog



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

  Posted by Barnsite, 09 May 2016 - - - - - - · 5235 views

Okay, expanding on what I did yesterday.I Built a table, called ExclusionList with one field, ExcludedTextE.g.Then created a function:CREATE FUNCTION [dbo].[udf_clean_string] ( @string VARCHAR(100) ) RETURNS VARCHAR(100)ASBEGIN SELECT @string = REPLACE(@string,ExcludedText,'')FROM ExclusionListRETURN @stringYou can then use like this:SELECT d...


Remove Characters in String T-SQL with No Loop

  Posted by Barnsite, 09 May 2016 - - - - - - · 4920 views

Ok, I’ve seen many ways to do this using loops, but nothing in plain T-SQLLet’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 names for exporting. However, many had / or * in the names.One thing I hate in T-SQL is loops, so having only found looping ways...


Add child items to ToolStripMenuItem using C# – C Sharp

  Posted by Barnsite, 22 January 2013 - - - - - - · 4825 views

I wanted to be able to populate menu items from a database, i.e. I had a Print Document top level menu item and I wanted to be able to populate the children from the database dynamically with each available document.
The theory was this:
1. Use the MouseHover event for the main menu item
2. When the user hovers over the item, get the list of...


Shuffle an Array in C#

  Posted by Barnsite, 15 January 2013 - - - - - - · 2054 views

As part of a basic guessing game I wanted to be able to shuffle an array of n chars into a random order.
The method I decided to use was the following.
Create a loop to iterate n times (where n is the number of elements in the array).  Randomly select one array element and add this to a new array.  Replace the removed item with the last item in...


Loading Data into a DataReader and Looping Through Records OLEDB / C#

  Posted by Barnsite, 24 December 2012 - - - - - - · 1482 views
programming
Just a quick example of loading data into a data reader using C#.  My data source is MS SQL Server in this case, although you would just need the correct OLEDB connection string to use any other data source.

//database connection string & SQL Statement to return SERVICE_LEVEL_ID and DEFINITION from a table called property.SERVICE_LEVEL
string...


Changing Default Parameter Value SSRS (SQL Server Reporting Services) 2008

  Posted by Barnsite, 17 December 2012 - - - - - - · 1616 views
programming
If you’re here you have probably found that if you’ve deployed a report to your server updating the default parameter values and redeploying has no effect on the server report.
E.g. I had a report with an integer parameter with a default of 25 that had been deployed to the server.  On my development machine I updated the default value and...


Image Slideshow on Windows Form C# with Timer Control

  Posted by Barnsite, 07 December 2012 - - - - - - · 2646 views
programming
Quick example of how to display an image control that loops through a folder of images.
Firstly drop a timer control onto your form (name: tmrNextImage), set the Interval to 1000 milliseconds (1 second) and set enabled to true.
Next drop a PictureBox control onto your form (name: imgPicture) and set SizeMode to Zoom (this will force your image to fit the...


Find all Subdirectories from a given path using C# – With Error Handler

  Posted by Barnsite, 07 December 2012 - - - - - - · 640 views
programming
In my earlier post () I showed how you can iterate through folders and add the folder names to a list (lstDirs).  The problem with this code was that if you encountered a folder you didn’t have access to it all fell over.  Below I’ve added a function to test the folder access (canReadDir()), if the folder is inaccessible the path is added to...


Search for Value in Multiple Columns SQL Server T-SQL

  Posted by Barnsite, 04 December 2012 - - - - - - · 734 views
programming
Having to write some SQL SELECT’s on some un-normalized tables left me thinking there has to be a tidier way. I started with:

SELECT
*
FROM bags.SAC_LOG
WHERE [SCANNERID_1] = @SCAN_ID
OR [SCANNERID_2] = @SCAN_ID
OR [SCANNERID_3] = @SCAN_ID
OR [SCANNERID_4] = @SCAN_ID
OR [SCANNERID_5] = @SCAN_ID
OR [SCANNERID_6] = @SCAN_ID
OR [SCANNERID_7] =...


Browse for SQL Server 2008 R2 Installation Media

  Posted by Barnsite, 03 December 2012 - - - - - - · 1194 views
programming
When running the SQL Server Installation Centre I was receiving the above error.  This seems to be caused by the software being installed to a temp folder which is subsequently deleted post install.
Mine had been installed from a folder on the network.  Even pointing to this folder when prompted didn’t resolve the problem.
Solution that worked for...