Posts

Showing posts from April, 2014

Generate unique number in sql server

DECLARE @Result nvarchar(255);
    DECLARE @Random float;
    SET @Random  =  RAND( (DATEPART(mm, GETDATE()) * 100000 )
                    + (DATEPART(ss, GETDATE()) * 1000 )
                    + DATEPART(ms, GETDATE() )) ;
    SET @Random  = (10000000000) * @Random;
    Set @Result = convert(nvarchar(25), convert(bigint, @Random));

    select  'A_ '+ @Result

SELECT  CONVERT(varchar(255), NEWID()) RandomNumber;

IF NOT EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Table_Name' AND  COLUMN_NAME = 'Column_Name')
                ALTER TABLE  'Table_Name' ADD 'Column_Name ' nvarchar(255)  NULL

check validation inside gridview using jquery

$(document).ready(function () {

                    $('input[id*="btnSave"]').bind('click', variationSupportValidation);
                });

    function variationSupportValidation() {                                           
                    var shouldShowAlert = false;
                    $('div[id*="rgrdCastItemlevel"]').find('input').each(function (i) {

                        if ($.trim($(this).val()).length > 0) {
                            var tempSupportPercent = $.trim($(this).val()).replace(/[%,]+/g, '');
                            if (tempSupportPercent >= 100) {                                                       
                                shouldShowAlert = true;
                            }
                        };
                    });

                    if (shouldShowAlert) {
                        alert("Validation message");
                        return !shouldShowAlert;
        …

Call Methods on event based in jquery

$(document).ready(function () {
        $('input[id$="ControlId"]').focusout(validateAmountInput);
});

function validateAmountInput(sender, args) {

}

$(document).ready(function () {
$('input[id*="ControlId"], [id*=" ControlId2"]').focusout(autoCalculateProjTrByGrant);

});


function autoCalulateGrantAsAPercentage() {

}

Auto generate Sequence Number in Sql server

create function [Function_Name]
(
@Parameter        TINYINT
,@Parameter2        TINYINT

)
RETURNS NVARCHAR(100)
AS
BEGIN

    DECLARE      @Name    NVARCHAR(100)
            , @Code            NVARCHAR(25)
            , @AutoGenerateNumber VARCHAR(100)


    SELECT @Name    = 'CompanyName'   
          ,@Code = 'Comapny Code'
    FROM dbo.[TableName] FBS
    INNER JOIN [dbo].[TableName2] FB
        ON FBS.ColumnName=FB.ColumnName
    INNER JOIN [dbo].[TableName3] SM
        ON SM.ColumnName=FBS.ColumnName
    WHERE FBS.ColumnName = @Parameter
        AND FBS.ColumnName = @Parameter2

    SELECT @AutoGenerateNumber=@Name+ '/'+@Code +'/'+right('0000' + CONVERT(VARCHAR(50),MAX(REVERSE(SUBSTRING(REVERSE(ReferenceNo),0,CHARINDEX('/',REVERSE(ISNULL(ReferenceNo,0)))))+1)),4)  
    FROM dbo.TableName A
    WHERE A.FundBlockId = @Parameter
        AND A.SchemeId =@Parameter2

    IF @AutoGenerateNumber IS NULL
        SET @AutoGenerateNumber=@Name+ '/'+@Cod…