Oracle Equivalent for “Use Database” Command
ALTER SESSION SET CURRENT_SCHEMA = schema
Oracle Equivalent for “Use Database” Command
ALTER SESSION SET CURRENT_SCHEMA = schema
Suppose values in your fields contain a period, and you want to return all characters that come before it. This is how you do in SQL Server:
select substring(column1, 1, charindex(’.', column1)-1 )
from myTable
Capitalize First Letter in JavaScript
Here is a function based on excellent code from Philip M at http://www.codingforums.com/showthread.php?t=168661 that capitalizes the first letter of each word:
function caps(str){
return str.toLowerCase().replace(/\b[a-z]/g,function(w){return w.toUpperCase()});
}
Check if Column is Empy in SQL Server
WHERE datalength(ColumnName)> 0 shows non-empty fields
Replace single quotes in transact-sql
If you have single quotes in your text values, and you need to insert them in a SQL Server database the recommended approach is to use parameterized stored procedures. They will handle single quotes seamlessly.
However, there may be cases when you may need to construct an insert statement without resorting to parameters. In such cases, to handle text that contains single quotes you may have to use the Transact-SQL Replace function:
REPLACE ( string_expression , string_pattern , string_replacement )
An example that escapes single quotes by adding another single quote before it:
Declare @temp as varchar(64)
Set @temp= (select … from …)
Set @temp = Replace(@temp, ‘”’,””'’)
In other words, you need 4 single quotes as a second argument, and 6 single quotes as a second argument to escape single quotes.
Export Unicode From GridView to Excel
This solution was found on http://razvan.cosma.name/weblog/index.php?entry=entry090116-161656
private void ExportToExcel(string strFileName, GridView gv)
{
Response.ClearContent();
Response.ContentType = "application/excel";
Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
Response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.Unicode;
Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(sw.ToString());
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
Some Regular Expressions for Java
If you need to find text lines that start with an alphanumeric characters:
String reg ="\\w+";
In other words, an alphanumeric character that gets repeated 1 or more times.
To find text lines that start with a whitespace and contain other characters after it, use the following regex:
String reg = "\\s.+";
That is, first find a whitespace, then any character repeated 1 or more times.
Select Individual Columns From Table Information Schema
The ‘desc’ command to get a list of table fields that is common in Oracle and MySql will fail in SQL Server. It turns out it is not sql-standard compliant. Instead, SQL Server uses the following command:
sp_columns myTableName
This will display detailed information about table structure.
If you need just individual columns, use the following command:
select column_name, data_type, character_maximum_length, *
from information_schema.columns
where table_name = ‘myTableName’
order by ordinal_position
Upload Excel File Without Saving It
Here is a discussion of the captioned issue with a solution posted at the end of the page, pointing to a third-party solution.
Split a string into words in Java
Use a Pattern class from the java.util.regex package to split a long string into separate words in Java.
A Pattern is a compiled representation of a regular expression.
String str = "a very long string possibly with line breaks , tab delimiters etc";
Pattern p = Pattern.compile("[,\\s]+");
String[] arr = p.split(str);
I use this function found on the stackoverflow site to check whether a string is a number:
return System.Text.RegularExpressions.Regex.IsMatchIt recognizes integers and decimals. However, it fails on comma separators.
More tips at http://c-sharpe.blogspot.com/
Translate Column Reference to Column Index
Here is a VBA function that converts a column reference to a column index.
Function ColRef2ColNo(ColRef As String) As Integer
ColRef2ColNo = 0
On Error Resume Next
ColRef2ColNo = Range(ColRef & "1").Column
End Function
A good explanation of the JavaScript event delegation can found in this SitePoint article.
Adjusting the left property will have no effect on the matching elements unless those elements have their CSS position set to relative or absolute. The default CSS position for all block‑level elements is static.
If you put an absolutely positioned box inside a relatively positioned box, it moves with that box. It is absolutely relative!
Prevent browser from jumping to top of the page
When you use href=’#’ and provide a JavaScript function for the onclick event, the browser always jumps to the top of the page after executing the JavaScript function. The simple way to avoid the jumping effect is to include a ‘return false’ statement after the call to the JavaScript function. Example:
<a href=’#’ onclick=’fnClick(this); return false;’>Do something </a>
If you use .NET 1.1, you can set "Smartnavigation=true" in Document properties.