Geeks With Blogs
Robin Hames Hints, tricks and tips relating to MS SQL Server and .NET August 2009 Entries
Trim Leading Zeros from a string in SQL Server
This user defined function is based on a function posted at this very useful site: http://www.sql-server-helpe... I have modified it slightly to handle spaces within the input string; by first replacing any existing spaces with ‘¬’ (this seems to be a suitably obscure character that is never likely to occur in the input string). CREATE FUNCTION RemoveLeadingZerosFromVarChar ( -- Add the parameters for the function here @inputStr varchar(max) ) RETURNS varchar(max) ......

Posted On Friday, August 21, 2009 9:16 AM

Using int.TryParse() within a LINQ where clause
I pretty new to LINQ, and I’m keen to get more experience using it, so whenever an opportunity arises I like to try writing LINQ queries. I needed to write a method to extract a comma separated list of numbers from a config file, and return this as List<int>. I was looking at ways to do this using LINQ, but hit a problem. I wanted my LINQ query to filter out any values in the CSV string that could not be parsed as an int, without causing an exception. Using int.TryParse() seemed like a possible ......

Posted On Wednesday, August 12, 2009 10:37 AM

Getting the Time part only from a SQL Server DateTime
Just some code to get the time part only from a DateTime field (is SQL Server 2000 or 2005), with the date set to a reference date declare @timetest datetime declare @refdate datetime set @timetest = getdate() set @refdate = '30 Dec 1899 00:00:00' select @timetest , @refdate , dateadd(day, datediff(day, @refdate , @timetest), @refdate ) -- date part only , dateadd(day, datediff(day, @refdate , @timetest) * -1, @timetest) -- time part only, with reference date Instead of @refdate, you could use 0 ......

Posted On Tuesday, August 11, 2009 12:24 PM

Copyright © Rhames | Powered by: