Excel search from right to left


Function RevInStr(findin As Range, tofind As String) As Integer

' Chris Rae's VBA Code Archive - http://chrisrae.com/vba

Dim findcha As Integer

For findcha = Len(findin) - Len(tofind) + 1 To 1 Step -1

If Mid(findin, findcha, Len(tofind)) = tofind Then

RevInStr = findcha

Exit Function

End If

Next findcha

' Defaults to zero anyway (tsk, tsk, etc)

End Function

How to: change SQL server instance name

SQL server typically gets its instance name from underlining machine name when the SQL server was first installed. If the machine name has been changed, the SQL server instance name will be in-sync with network name. It could cause lots of wired behavior. If the following two command give you different name, then you better change your instance name.
sp_helpserver
select @@servername

To change instance name run this:

sp_dropserver 'old_name'
go
sp_addserver 'new_name','local'
go

Then restart the SQL server service.

A simple Sql cursor sample


USE FencoDW
GO

DECLARE @ID INT, @PR varchar(50)
DECLARE @getID CURSOR
SET @getID = CURSOR FOR
SELECT [Load Number], [Primary Reference(s)]
FROM Accounting.TransplaceLoadInfo

OPEN @getID
FETCH NEXT
FROM @getID INTO @ID, @PR
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @ID
PRINT @PR

INSERT INTO dbo.T1 ([Load Number], [Primary Reference(s)])
SELECT @ID, [Val] from dbo.ParseCSV(@PR, ',')

FETCH NEXT
FROM @getID INTO @ID, @PR
END
CLOSE @getID
DEALLOCATE @getID
GO