How can I generate a temporary table filled with dates in SQL Server 2000?

I needed something similar, but all DAYS instead of all MONTHS. Using the code from MatBailie as a starting point, here’s the SQL for creating a permanent table with all dates from 2000-01-01 to 2099-12-31: CREATE TABLE _Dates ( d DATE, PRIMARY KEY (d) ) DECLARE @dIncr DATE = ‘2000-01-01’ DECLARE @dEnd DATE = ‘2100-01-01’ … Read more

INSERT INTO @TABLE EXEC @query with SQL Server 2000

N.B. – this question and answer relate to the 2000 version of SQL Server. In later versions, the restriction on INSERT INTO @table_variable … EXEC … were lifted and so it doesn’t apply for those later versions. You’ll have to switch to a temp table: CREATE TABLE #tmp (code varchar(50), mount money) DECLARE @q nvarchar(4000) … Read more

Regular Expressions in SQL Server servers?

For SQL Server 2000 (and any other 32 bit edition of SQL Server), there is xp_pcre, which introduces Perl compatible regular expressions as a set of extended stored procedures. I’ve used it, it works. The more recent versions give you direct access to the .NET integrated regular expressions (this link seems to be dead, here … Read more

Query extremely slow in code but fast in SSMS

Your code in SSMS is not the same code you run in your application. This line in your application adds a NVARCHAR parameter: ada.SelectCommand.Parameters.AddWithValue(“@clientID”, ClientID); while in the SSMS script you declare it as VARCHAR: declare @clientID varchar(200) Due to the rules of Data Type Precedence the Where client_id = @clientID expression in your query … Read more

Find index of last occurrence of a sub-string using T-SQL

Straightforward way? No, but I’ve used the reverse. Literally. In prior routines, to find the last occurence of a given string, I used the REVERSE() function, followed CHARINDEX, followed again by REVERSE to restore the original order. For instance: SELECT mf.name ,mf.physical_name ,reverse(left(reverse(physical_name), charindex(‘\’, reverse(physical_name)) -1)) from sys.master_files mf shows how to extract the actual … Read more

How to create the linked server for SQL Server 2008 where we have the database from 2000 and 2005

There are a few different ways that you can create a linked server in SQL Server you can use the GUI in SQL Server Management Studio or via a script. Using the instructions on MSDN you can do the following: Click Start, click All Programs, click Microsoft SQL Server 2005 or Microsoft SQL Server 2008, … Read more

techhipbettruvabetnorabahisbahis forumu