You must Sign In to post a response.
  • Category: .NET

    Regarding Varbinary Convertion in sql

    Hi

    I have one column with varbinary datatype
    in sql server and i inserted guid in my varbinary data type column
    how to reverse value after insert sql server or c# how will get this value.
  • #768285
    You can use following code snippet for reverse value after insert sql server or c#
    DECLARE @temp TABLE
    (
    ID INT IDENTITY(1,1)
    , Case_YourName NVARCHAR(50)
    , Case_Description NVARCHAR(50)
    )

    INSERT INTO @temp (Case_YourName, Case_Description)
    VALUES
    ('Phagu Mahato ', 'Will Management'),

    UPDATE @temp
    SET Case_YourName = SUBSTRING(Case_YourName, CHARINDEX(' ', Case_YourName), LEN(Case_YourName)) + ' ' + SUBSTRING(Case_YourName, 1, CHARINDEX(' ', Case_YoorName))
    SELECT * FROM @temp


    Or use this command
     INSERT Mytable (col1, col2) OUTPUT INSERTED.IDCol VALUES (@param1, @param2);

  • #768315
    Hi,

    UniqueIdentifier is one which gives you unique set of number which we cant keep it as Numeric or even integer because the range of GUID is bigger than any datatypes of numeric.

    We can do the following step to make this conversion works.



    CREATE FUNCTION STRTOUID()
    {
    DECLARE @guid VARCHAR(50)
    SET @guid = 'a89b1acd95016ae6b9c8aabb07da2010'
    SELECT CAST(
    SUBSTRING(@guid, 1, 8) + '-' + SUBSTRING(@guid, 9, 4) + '-' + SUBSTRING(@guid, 13, 4) + '-' +
    SUBSTRING(@guid, 17, 4) + '-' + SUBSTRING(@guid, 21, 12)
    AS UNIQUEIDENTIFIER)
    }


    You can invoke this function anywhere in the stored procedure and perform your operation.

    Thanks,
    Mani


  • Sign In to post your comments