Tuesday, April 23, 2013

Extract Excel input string "+"

DECLARE @test varchar(100) = '+HARIA+123+MALE+STUDENT+HOUSEWIFE+jhgjh+54545+hgdfjhg+xxxxc'

SELECT TOP 8000
    Num
INTO
    #Number
FROM
    (
    SELECT
       ROW_NUMBER() OVER (ORDER BY c1.object_id) AS Num
    FROM
       sys.columns c1, sys.columns c2, sys.columns c3
    ) N

SELECT
    ROW_NUMBER() OVER (ORDER BY Num) AS Rank,
    LTRIM(RTRIM(SUBSTRING(@test,
                          Num,
                          CHARINDEX('+', @test + '+', Num) - Num
                ))) AS Value
FROM
    #Number
WHERE
    Num <= LEN (@test)
    AND
    SUBSTRING('+' + @test, Num, 1) = '+'

DROP TABLE #Number
Source :stackoverflow

Sunday, April 7, 2013

Excel vba 2010 browse select folder and open file

Private Sub CommandButton1_Click()

Dim myfile As Variant
Dim counter As Integer
Dim path As String
myfolder = "c:\tmp\"
ChDir myfolder
myfile = Application.GetOpenFilename(, , , , True)
counter = 1
If IsNumeric(myfile) = True Then
MsgBox "No files selected"
End If
While counter <= UBound(myfile)
path = myfile(counter)
Workbooks.Open path
counter = counter + 1
Wend

End Sub