Below query is used to retrieve DATE in required format through SQL Query.
'SELECT CONVERT(VARCHAR(100),FieldName, 101) AS Sample_date FROM tableName'
Here note that FieldName must of DATETIME or DATE Datatype. Also note that output will be in STRING or VARCHAR Datatype.
You can try out with 100 to 116 Different date format as per your requirement.
This blog is specially design to help out various queries related with ASP.NET, PHP, ASP, HTML, SQL SERVER, CSS, JavaScript...
Search me out HERE!!
ROUND UP "FLOAT" Value in SQL Query.
Below query shows how to round up FLOAT datatype field in SQL Query itself.
SELECT ROUND(FieldName,2) AS TEST FROM TableName
Here there will be '2' digits after decimal point. You can change this number as per your requirement.
SELECT ROUND(FieldName,2) AS TEST FROM TableName
Here there will be '2' digits after decimal point. You can change this number as per your requirement.
Use of ISNULL in SQl Server
Here is the solution to replace NULL with some value in Query itself.
Consider following table:
TESTING
Now Run this Query
SELECT ISNULL(data,'0') AS RESULT FROM TESTING
OUTPUT WILL BE:
Consider following table:
No | Data |
1 | ASP.NET |
2 | PHP |
3 | null |
Now Run this Query
SELECT ISNULL(data,'0') AS RESULT FROM TESTING
OUTPUT WILL BE:
No | Data |
1 | ASP.NET |
2 | PHP |
3 | 0 |
How to use REPLACE & TRANSLATE in SQL Server
Here is the Solution how you can replace Character or Word in SQL QUERY itself.
Query:
SELECT REGCODE, REGTYPE, TRANSLATE(REGTYPE,'R','K') AS RESULT1, REPLACE(REPLACE(REGTYPE,'R4','FOUR'),'R5','FIVE') AS RESULT2 FROM REGION
GO
Here in output REPLACE column will be displayed in which as per required we can replace our desired value in column depending on value of particular column.
OUTPUT
Query:
SELECT REGCODE, REGTYPE, TRANSLATE(REGTYPE,'R','K') AS RESULT1, REPLACE(REPLACE(REGTYPE,'R4','FOUR'),'R5','FIVE') AS RESULT2 FROM REGION
GO
Here in output REPLACE column will be displayed in which as per required we can replace our desired value in column depending on value of particular column.
REGCODE | REGTYPE | RESULT1 | RESULT2 |
1 | R4 | K4 | FOUR |
1 | R5 | K5 | FIVE |
CONVERT NUMBER INTO WORD IN C# APPLICATION
public string IntegerToWords(long inputNum) {
int dig1,dig2,dig3,level=0,lasttwo,threeDigits;
string retval="";
string x="";
string[] ones={
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen"
};
string[] tens={
"zero",
"ten",
"twenty",
"thirty",
"forty",
"fifty",
"sixty",
"seventy",
"eighty",
"ninety"
};
string[] thou={
"",
"thousand",
"million",
"billion",
"trillion",
"quadrillion",
"quintillion"
};
bool isNegative=false;
if (inputNum < 0) { isNegative=true; inputNum*=-1; } if (inputNum==0) return ("zero"); string s=inputNum.ToString(); while (s.Length>0) {
// Get the three rightmost characters
x=(s.Length<3) ? s : s.Substring(s.Length - 3, 3); // Separate the three digits threeDigits=int.Parse(x); lasttwo=threeDigits % 100; dig1=threeDigits / 100; dig2=lasttwo / 10; dig3=(threeDigits % 10); // append a "thousand" where appropriate if (level>0 && dig1+dig2+dig3>0) {
retval=thou[level] + " " + retval;
retval=retval.Trim();
}
// check that the last two digits is not a zero
if (lasttwo>0) {
if (lasttwo<20) // if less than 20, use "ones" only retval=ones[lasttwo] + " " + retval; else // otherwise, use both "tens" and "ones" array retval=tens[dig2] + " " + ones[dig3] + " " + retval; } // if a hundreds part is there, translate it if (dig1>0)
retval = ones[dig1] + " hundred " + retval;
s=(s.Length - 3)>0 ? s.Substring(0,s.Length - 3) : "";
level++;
}
while (retval.IndexOf(" ")>0)
retval=retval.Replace(" "," ");
retval=retval.Trim();
if (isNegative)
retval="negative " + retval;
return (retval);
}
NOTE : You need to create .cs file. Include above code in it and then use Function wherever applicable in your application.
CSS Transparency Settings for All Browsers..
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
NOTE:
* opacity: 0.5; This is the “most important” one because it is the current standard in CSS. This will work in most versions of Firefox, Safari, and Opera. This would be all you need if all browsers supported current standards. Which, of course, they don’t.
* filter:alpha(opacity=50); This one you need for IE.
* -moz-opacity:0.5; You need this one to support way old school versions of the Mozilla browsers like Netscape Navigator.
* -khtml-opacity: 0.5; This is for way old versions of Safari (1.x) when the rendering engine it was using was still referred to as KTHML, as opposed to the current WebKit.
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
NOTE:
* opacity: 0.5; This is the “most important” one because it is the current standard in CSS. This will work in most versions of Firefox, Safari, and Opera. This would be all you need if all browsers supported current standards. Which, of course, they don’t.
* filter:alpha(opacity=50); This one you need for IE.
* -moz-opacity:0.5; You need this one to support way old school versions of the Mozilla browsers like Netscape Navigator.
* -khtml-opacity: 0.5; This is for way old versions of Safari (1.x) when the rendering engine it was using was still referred to as KTHML, as opposed to the current WebKit.
TO USE DIFFERENT STYLE.CSS FOR DIFFERENT BROWSER
<link href="style.css" type="text/css" rel="stylesheet" />
<!--[if IE 6]>
<link href="style_ie.css" type="text/css" rel="stylesheet" />
<![endif]-->
NOTE : Use Above code in your HEAD. Here style.css will be applied for all browser by default. But style_ie.css will be applied only to IE.
<!--[if IE 6]>
<link href="style_ie.css" type="text/css" rel="stylesheet" />
<![endif]-->
NOTE : Use Above code in your HEAD. Here style.css will be applied for all browser by default. But style_ie.css will be applied only to IE.
Subscribe to:
Posts (Atom)