Wednesday, August 29, 2012

ASP.NET - Display pdf From BLOB


Imports System.IO


Private Sub DisplayPdfFromBLOB(ByVal adt As DataTable)

        Dim blob() As Byte


        Try

            blob = CType(adt(0)("form_document"), Byte())
            Dim ms As New MemoryStream(blob)

            Response.ContentType = "application/pdf"
           ms.WriteTo(Response.OutputStream)
            Response.Flush()

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

Friday, August 3, 2012

SQL - Get Left Part of String From 2nd Space

If you have some text value and you need to get the left part of the string from the 2nd space, here is a technique I figured out that works.

declare @some_text as nvarchar(20) = 'through 123 some text';

select ltrim(rtrim(left(@some_text, charindex(' ', @some_text, charindex(' ', @some_text)+1))))


You could apply the same logic to go from the nth space in the occurrence, it would become more complex.