Tuesday 17 October 2017

Sql server Sort date format


select CONVERT(varchar(12),getdate(),1) --// Result 10/18/17
select CONVERT(varchar(12),getdate(),2) --// Result 17.10.18
select CONVERT(varchar(12),getdate(),3) --// Result 18/10/17
select CONVERT(varchar(12),getdate(),4) --// Result 18.10.17
select CONVERT(varchar(12),getdate(),5) --// Result 18-10-17
select CONVERT(varchar(12),getdate(),6) --// Result 18 Oct 17
select CONVERT(varchar(12),getdate(),7) --// Result Oct 18, 17
select CONVERT(varchar(12),getdate(),8) --// Result 11:16:55
select CONVERT(varchar(12),getdate(),9) --// Result Oct 18 2017
select CONVERT(varchar(12),getdate(),10) --// Result 10-18-17

select CONVERT(varchar(12),getdate(),11) --// Result 17/10/18
select CONVERT(varchar(12),getdate(),12) --// Result 171018
select CONVERT(varchar(12),getdate(),13) --// Result 18 Oct 2017            select CONVERT(varchar(12),getdate(),14) --// Result 11:15:40:210

Sunday 15 October 2017

Ajax FilteredTextBoxExtender on multiline TextBox in asp.net allow Enter Key

//

protected void Page_Load(object sender, EventArgs e)
    {
        FilteredTextBoxExtender12.ValidChars = FilteredTextBoxExtender12.ValidChars + "\r\n";

    }

Monday 9 October 2017

Covert to Currency or datetime format in sql for 2012+ version


Example 1:
DECLARE @mney money = '125000';
SELECT FORMAT ( @mney, 'C') AS MyMoney;
Result:
$125,000.00

Example 2:
DECLARE @mney money = '125000';
SELECT FORMAT ( @mney,'C', 'ta-IN') AS MyMoney;
Result
ரூ 1,25,000.00

Example 3:
DECLARE @mney money = '125000';
SELECT FORMAT ( @mney,'C', 'zh-TW') AS MyMoney;
Result:
NT$125,000.00

Example 4:
set language british
DECLARE @mney money = '125000';
SELECT FORMAT ( @mney, 'C') AS MyMoney;
Result
£125,000.00

Example 5:
DECLARE @num bigint = 5
SELECT FORMAT ( @num, '00.000%') AS MyMoney;
Result:
500.000%

Example set 1:
SELECT Format(1222.4, '##,##0.00')   -- Returns "1,222.40".
SELECT Format(345.9, '###0.00')   -- Returns "345.90".
SELECT Format(15, '0.00%')   -- Returns "1500.00%".

Example set 2
DECLARE @date datetime =getdate()
SELECT  Format(@date , 'h:m:s')   -- Returns "1:10:47".
SELECT Format(@date , 'hh:mm:ss tt')   --Returns "01:10:47 AM".
SELECT Format(@date , 'dddd, MMM d yyyy')   --Returns "Thursday, Dec 22 2011"

Example Set 3:
SELECT  Format(getdate(), 'M/d/yyyy H:mm tt','en-US') --Returns 12/22/2011 1:14 AM

SELECT  Format(getdate(), 'M/d/yyyy H:mm tt zzz','en-US') --12/22/2011 1:15 AM -05:00

Convert Data in currency format using sql server all version

// Query

create function Currency_Format(@ValToConver float,@CommaInt int)
returns varchar(200)
as
begin
  declare @RepsVal varchar(50)
  declare @p1 varchar(40)
  declare @p2 varchar(10)

  set @RepsVal = replace(convert (varchar(20), convert(money, @ValToConver), 3 ) , ',','')
  set @p1 = left(@RepsVal, charindex('.', @RepsVal)-1)
  set @p2 = substring(@RepsVal, charindex('.', @RepsVal), 10)

  set @RepsVal = right(@p1, 3) + @p2
  set @p1 = left(@p1, len(@p1)-3)

  while (@p1<>'')
  begin
    set @RepsVal = right(@p1, @CommaInt) + ',' + @RepsVal
    if (len(@p1) > @CommaInt)
      set @p1 = left(@p1, len(@p1)-@CommaInt)
    else
      set @p1= ''
  end

  return(@RepsVal)

end


/// Result



Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...