Thursday, December 11, 2008

app_offline.htm ใน asp.net 2.0

อีกหนึ่ง feature ที่เป็นสิ่งใหม่ใน asp.net 2.0 ก็คือการสร้าง file app_offline.htm ไปวางไว้ใน web root เพื่อทำการบอก user ของเราว่าเวบของเราตอนนี้กำลัง update อยู่framework 2.0จะทำความรู้จักfileนี้เองโดยอัตโนมัติโดยที่เราไม่ต้องทำอะไรเลย ง่ายต่อการนำไปใช้
ข้อที่ควรระวังก็คือ ใน IE6 ต้องไป config browser ตรง

Tools->Internet Options->Advanced tab ->"Show Friendly Http Errors Message"

ถ้าไม่เลือก option นี้เอาไว้เวลา user เข้าใช้จะแสดง error 404 แทน วิธีที่แก้ใขโดยที่ user ไม่ต้องเลือกตรง Option นี้ก็คือการสร้าง app_offline.htm ให้มีขนาด file มากกว่า 512 byte เพื่อให้แน่ใจว่า user ทุกคนเข้าเวบเรามาแล้วแสดงหน้านี้ตลอด หาก file app_offline.htm ของเรามีไม่ถึง 512 byte อาจใช้วิธีการใส่ comment ลงไปเพื่อให้ file มีขนาดเกิน 512 byte ดังตัวอย่างด้านล่าง


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> My Under ConStruction</TITLE>
</HEAD>
<BODY>
<h1>This Site Under Construction N o w !...</h1>
<!--
this coment text
<h1>This Site Under Construction N o w !...</h1>
<h1>This Site Under Construction N o w !...</h1>
<h1>This Site Under Construction N o w !...</h1>
<h1>This Site Under Construction N o w !...</h1>
<h1>This Site Under Construction N o w !...</h1>
<h1>This Site Under Construction N o w !...</h1>
<h1>This Site Under Construction N o w !...</h1>
<h1>This Site Under Construction N o w !...</h1>
<h1>This Site Under Construction N o w !...</h1>
<h1>This Site Under Construction N o w !...</h1>
-->
</BODY>
</HTML>


ที่มา: http://codesnippet.exteen.com/20060628/app-offline-htm-asp-net-2-0

Thursday, November 6, 2008

An ASP.NET setting has been detected that does not apply in the Integrated managed pipeline mode



จะเจอ error นี้เมื่อสร้าง application หรือ vertual directory ใหม่แล้วเข้าใช้เว็บไซต์ (IIS7)

แก้โดยกด “Windows” + “R” แล้วพิมพ์ %SystemRoot%\system32\inetsrv\appcmd migrate config "Default Web Site/" กด OK เป็นอันเสร็จ

ลอง refresh หน้าจอใหม่ก็จะ run application ได้

http://blog.benhall.me.uk/2008/05/aspnet-setting-has-been-detected-that.html
http://www.monavista.com/webboard/showthread.php?t=4839

Thursday, October 2, 2008

Visual Studio 2008 Error

SOFTWARE:
Visual Studio 2008 Team Database Edition
SQL Server 2005 Enterprise SP2

ERRORS:
"The database that you selected is not supported"

Unable to add data connection.
Could not load file or assembly
'Microsoft.SQLServer.Management.Sdk.Sfc, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its
dependencies. The sytem cannot find the file specified.

STEPS TO REPRODUCE:
Data > Schema Compare
New Connection..
Type in all info > select database name (it IS seeing all the
databases on the server)
click Test Connection
"Test Connection suceeded"
Click OK
"The database that you selected is not supported"

Does the same thing if I do
New Project > Visual C# > Database > SQL Server Project
Server Explorer
Add New Connection
Error:
Unable to add data connection.
Could not load file or assembly
'Microsoft.SQLServer.Management.Sdk.Sfc, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its
dependencies. The sytem cannot find the file specified.

TROUBLESHOOTING STEPS ALREADY TAKEN:
I tried totally uninstalling Visual Studio 2008, 2005, and SQL 2005
Workstation Components/Client Tools..
Installed Visual Studio 2008
Tried same thing, got same error message.
Installed SQL 2005 Workstation Components / Client Tools
Installed SQL 2005 SP2
Tried same thing, got same error message.

SOLUTION: Download and install following from Microsoft.

- Microsoft SQL Server 2008 Native Client
- Microsoft SQL Server System CLR Types
- Microsoft SQL Server 2008 Management Objects

These features can be downloaded from:
http://www.microsoft.com/downloads/details.aspx?FamilyId=C6C3E9EF-BA29-4A43-8D69-A2BED18FE73C&displaylang=en#filelist

Reference: http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.vstudio.general&tid=89ee0e86-b8fc-40a7-a0e1-51ac4033302e&cat=en_US_38f7e3d1-40bd-4daf-941f-f45d2ff6ff9b&lang=en&cr=US&sloc=&p=1

Monday, September 29, 2008

Run SQL Server 2000 DTS by Stored Procedure

1. “Windows” + “R” พิมพ์ dtsrunui ในช่อง Open แล้วกด OK



2. จะมีหน้าจอตามรูปด้านล่าง ใส่ ip server ในช่อง Server แล้วก็ใส่ Username และ Password ของ Server นั้น หลังจากนั้นกดปุ่ม ... หลังช่อง Package name จะมี list ของ DTS ใน Server นั้นมาให้เราเลือก เลือก DTS ที่ต้องการ แล้วกด OK



3. จากรูปในขั้นตอนที่แล้ว กดปุ่ม Advanced... จะได้หน้าจอตามรูปด้านล่าง กดปุ่ม Generate... จะมี command ขึ้นมาในช่องด้านหน้า ถ้าต้องการ Encrypt command เพื่อไม่ให้เห็น username และ password ให้ติ๊กถูกที่ Encrypt the command แล้วกด Generate อีกรอบ จะได้ command ที่ encrypt ไว้



4. หลังจากนั้นเอา command ที่ได้ มารันเหมือน SQL ปกติตาม code ด้านล่างนี้

EXEC master..xp_cmdshell {'command_string'}

http://msdn.microsoft.com/en-us/library/aa260689(SQL.80).aspx

Friday, September 19, 2008

Change datetime format and language on oracle

SELECT USERENV('language') from dual;

SELECT to_char(sysdate,'dd-mon-yyyy') FROM dual;

ALTER SESSION SET nls_language = 'AMERICAN';

SELECT to_char(sysdate,'dd-mon-yyyy') FROM dual;

ALTER SESSION SET nls_language = 'THAI';

SELECT to_char(sysdate,'dd-mon-yyyy') FROM dual;

http://www.dba-oracle.com/t_nls_date_format_sysdate.htm
http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html

Thursday, September 18, 2008

How to disable right click (Context Menu) on object in browser

Example in picture object:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<script language="javascript">
function disableContextMenu(obj) {
obj.oncontextmenu = function() {
return false;
}
}
function onLoad() {
disableContextMenu(document.getElementById("Pic1"));
}
</script>
</head>
<body onload="onLoad()">
<img id="Pic1" src="Pic1.jpg" alt="Picture" />
</body>
</html>

Or use this code:
<img id="Pic1" src="Pic1.jpg" alt="Picture" onmouseover="this.oncontextmenu=function(){return false}" />

Result:


XHTML table or div height in percentage (%)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Height 100%</title>
<style type="text/css">
html {
height:100%;
}
body {
height:100%;
margin:0;
padding:0;
}
</style>
</head>
<body>
<table style="height:100%; width:100%" border="1">
<tr><td>Top</td></tr>
<tr><td>Middle</td></tr>
<tr>
<td valign="bottom">
<table style="height:80px; width:100%" border="1">
<tr><td>bottom</td></tr>
</table>
</td>
</tr>
</table>
</body>
</html>

http://apptools.com/examples/tableheight.php
http://www.webmasterworld.com/forum83/200.htm

How to enable disable Ctrl + Alt + Del before logon XP or Vista

1. Windows + r and type control userpasswords2 (XP, Vista) or netplwiz (Vista only).




2. Goto advance tab on popup window. You can check the checkbox for enable ctrl + alt + del and uncheck the checkbox for disable ctrl + alt + del before logon.

Tuesday, September 16, 2008

Auto delete text on textbox on focus and restore text on unfocus

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title> new document </title>
<meta name="generator" content="" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>

<body>
<input type="text" id="email" value="Your e-mail here" onfocus="if(this.value=='Your e-mail here')this.value=''"
onblur="if(this.value=='')this.value='Your e-mail here'" />
</body>

</html>

Result:

Auto select all text on textbox

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title> new document </title>
<meta name="generator" content="" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>

<body>
<input type="text" id="email" value="Your E-mail here" onfocus="this.select()" />
</body>

</html>

Result:

Command prompts for Windows

http://en.kioskea.net/faq/sujet-403-command-prompts-for-windows

Monday, September 8, 2008

Crystal reports component for server

If you want to run ASP.NET website include crystal reports on web server. The web server will can't run its because server not install crystal report component.

The crystal reports component can found on developer's computer path below

Path:
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\CrystalReports\


Copy all to install on your server and run your website again.

Saturday, August 30, 2008

HTML CSS Box reference

Margin Border and Padding Reference


http://www.w3.org/TR/css3-box

Friday, August 29, 2008

Transparent DIV SPAN for Internet Explorer, Firefox

Style sheet:
.transparency
{
filter:alpha(opacity=60);
-moz-opacity: 0.6;
opacity: 0.6;
}

Apply code:
<div class="transparency">A transparent div.</div>
<img src="image_basic.jpg" alt="Sample" class="transparency" />

Thursday, August 21, 2008

How to vertical align the text within a text box

Use padding-top tab in CSS style.

For an example
<input type="text" style="width:140px; height:24px; padding-top:4px; font-family:Tahoma; font-size:18px" />

Result

MD5 on SQL Server

MD5 Hash SQL Server Extended Stored Procedure

http://www.codeproject.com/KB/database/xp_md5.aspx

SQL Server ROUND FLOOR CEILING function

SELECT ROUND(100.1145,2)
SELECT ROUND(100.1145,3)
GO

SELECT ROUND(123.45,-3), ROUND(123.45,-2), ROUND(123.45,-1), ROUND(123.45,0), ROUND(123.45,1), ROUND(123.45,2)
GO

SELECT FLOOR(123.45), FLOOR(-123.45), FLOOR($123.45), FLOOR($-123.45), FLOOR(123.9)
GO

SELECT CEILING(123.45), CEILING(-123.45), CEILING($123.45), CEILING($-123.45), CEILING(123.1)
GO

DECLARE @m MONEY
SET @m = 120.155 --SELECT @m = 120.155
SELECT @m
SELECT CONVERT(VARCHAR,@m)
GO

Monday, August 11, 2008

SQL Server Linked Server

Query from link server

for default instance name
SELECT * FROM [LinkServerName].DatabaseName.dbo.TableName

SELECT * FROM OPENQUERY([LinkServerName], 'SELECT * FROM TableName')

for other instance name
SELECT * FROM [LinkServerName\InstanceName].DatabaseName.dbo.TableName

SELECT * FROM OPENQUERY([LinkServerName\InstanceName], 'SELECT * FROM TableName')

other method
SELECT * FROM LinkServerName..UserName.TableName

Thursday, August 7, 2008

Oracle SQL *Plus write text to screen

SQL> set serveroutput on;
SQL> begin
2 dbms_output.put_line('Test ' || 'concat');
3 end;
4 /
Test concat

How to use trigger on Oracle

Prepare table
CREATE TABLE t1
(
c1 INTEGER,
c2 VARCHAR(10),
c3 VARCHAR(10)
)
CREATE TABLE t1_audit
(
a1 DATE,
a2 VARCHAR(3),
c1 INTEGER,
c2 VARCHAR(10),
c3 VARCHAR(10)
)
insert into t1 values (1,'111','aaa');
insert into t1 values (2,'222','bbb');
insert into t1 values (3,'333','ccc');
insert into t1 values (4,'444','ddd');

Create trigger
CREATE OR REPLACE TRIGGER t1_trig
AFTER UPDATE ON t1
FOR EACH ROW
BEGIN
IF(:NEW.c2 IS NULL) THEN
INSERT INTO t1_audit VALUES (SYSDATE, 'OLD', :OLD.c1, :OLD.c2, :OLD.c3);
INSERT INTO t1_audit VALUES (SYSDATE, 'NEW', :NEW.c1, :NEW.c2, :NEW.c3);
END IF;
END;

or use this command

CREATE OR REPLACE TRIGGER t1_trig
AFTER UPDATE ON t1
FOR EACH ROW
WHEN (NEW.c2 IS NULL)
BEGIN
INSERT INTO t1_audit VALUES (SYSDATE, 'OLD', :OLD.c1, :OLD.c2, :OLD.c3);
INSERT INTO t1_audit VALUES (SYSDATE, 'NEW', :NEW.c1, :NEW.c2, :NEW.c3);
END;

Test the trigger
UPDATE t1
SET t1.c2 = ''
WHERE t1.c1 = 3;

View result on t1_audit
07/08/2008 14:26:02 OLD 3 333 ccc
07/08/2008 14:26:02 NEW 3 ccc


http://infolab.stanford.edu/~ullman/fcdb/oracle/or-triggers.html
http://www.psoug.org/reference/table_trigger.html
http://www.exforsys.com/tutorials/oracle-9i/oracle-database-triggers.html
http://somkiat.exteen.com/20040715/trigger-short-tutorial

Wednesday, August 6, 2008

Upload file using ASP.NET 2.0

test

ความหมายของ PO PR

PO = Purchase Order คือใบสั่งซื้อที่เราจะส่งให้ผู้ขายเพื่อขอสั่งซื้อสินค้า

PR = Purchase Request หรือ Purchase Requisition ก็คือเอกสารภายใน คือเป็นใบขอสั่งซื้อที่ทางแผนกที่ต้องการสินค้าจะจัดตรียมขึ้นมาแล้วส่งไปให้ทางผู้จัดการฝ่ายลงชื่ออนุมัติสั่งซื้อ แล้วค่อยส่งต่อไปให้ฝ่ายจัดซื้อเพื่อดำเนินการสั่งซื้อสินค้าหรือจ้างทำของต่อไป

ในการสั่งซื้อสินค้า เราต้องทำการออก PR ให้แผนกจัดซื้อก่อน หลังจากนั้นแผนกจัดซื้อก็ทำการใส่ราคาที่จัดหามาได้
เมือได้ราคาแล้วเราก็สามารถออก PO เพื่อส่งให้ผู้ขายได้ครับ

How to delete file from ASP.NET

Import System.IO namespace
using System.IO

and use this code
try {
FileInfo TheFile = new FileInfo(MapPath(".") + "\\" + txtFile.Text);
if (TheFile.Exists) {
File.Delete(MapPath(".") + "\\" + txtFile.Text);
}
else {
throw new FileNotFoundException();
}
}
catch (FileNotFoundException ex) {
lblStatus.Text += ex.Message;
}
catch (Exception ex) {
lblStatus.Text += ex.Message;
}

Tuesday, August 5, 2008

How to insert values into an identity column in SQL Server

USE Northwind
GO

IF OBJECT_ID('IdentityTable') IS NOT NULL
DROP TABLE IdentityTable
GO

CREATE TABLE IdentityTable (
TheIdentity INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
TheValue NVARCHAR(20) NOT NULL )
GO

INSERT IdentityTable(TheIdentity, TheValue)
VALUES (1, 'First Row')
GO

Server: Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column in table 'IdentityTable' when IDENTITY_INSERT is set to OFF.

SET IDENTITY_INSERT IdentityTable ON

INSERT IdentityTable(TheIdentity, TheValue)
VALUES (3, 'First Row')

SET IDENTITY_INSERT IdentityTable OFF

SET IDENTITY_INSERT IdentityTable ON

INSERT IdentityTable(TheIdentity, TheValue)
VALUES (10, 'Row Ten')

SET IDENTITY_INSERT IdentityTable OFF

INSERT IdentityTable(TheValue)
VALUES ('Should be 11')

SELECT * FROM IdentityTable
GO

Result
---------------------
1 First Row
10 Row Ten
11 Should be 11

Show row number in SQL Server and Oracle

SQL Server:
USE Northwind
SELECT ROW_NUMBER() OVER (ORDER BY EmployeeID DESC) AS RowID, *
FROM EMPLOYEES ORDER BY FirstName

Show row number in SQL Server 2000, 2005
http://support.microsoft.com/kb/186133


Oracle:
SELECT rownum, column_name FROM user_tables

Show row number in Oracle
http://blog.lishman.com/2008/03/rownum.html

Friday, July 18, 2008

Command to view Environtment Variable

Start -> Run -> Type set and enter

Thursday, July 10, 2008

"NET USE" command for share folder

NET USE Parameter
C:\>net use /?
The syntax of this command is:

NET USE
[devicename *] [\\computername\sharename[\volume] [password *]]
[/USER:[domainname\]username]
[/USER:[dotted domain name\]username]
[/USER:[username@dotted domain name]
[/SMARTCARD]
[/SAVECRED]
[[/DELETE] [/PERSISTENT:{YES NO}]]

NET USE {devicename *} [password *] /HOME

NET USE [/PERSISTENT:{YES NO}]

Example
net use Y: /delete
net use Y: \\192.168.1.100\Folder1\Folder2 /USER:192.168.1.100\username password
start Y:\Folder3\Application.exe

Friday, June 20, 2008

Auto number in gridview





<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataKeyNames="ProductID,ProductName"
DataSourceID="SqlDataSource1"
BackColor="White"
BorderColor="#3366CC"
BorderStyle="None"
BorderWidth="1px"
CellPadding="4"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<RowStyle BackColor="White" ForeColor="#003399" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>NO</HeaderTemplate>
<ItemTemplate><%#Container.DataItemIndex+1%></ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" />
</Columns>
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<AlternatingRowStyle BackColor="#CCFFFF" />
</asp:GridView>

Reference

Single quote in sql

USE Northwind

SELECT CHAR(39)+ CompanyName FROM Customers

SELECT a='Thailand''s', b='Thailand'+'''s'

Thursday, June 19, 2008

How to use variable as column Name

USE Northwind

DECLARE @SqlQuery VARCHAR(1000)
DECLARE @ColumnName VARCHAR(100)
DECLARE @TableName VARCHAR(100)

SET @ColumnName = N'Address'
SET @TableName = N'Customers'
SET @SqlQuery = N'SELECT '+ @ColumnName+ ' FROM ' + @TableName

EXEC (@SqlQuery)

Friday, June 6, 2008

Error 7405: Heterogeneous queries (SQL Server 2000)

ก่อนคำสั่ง Create Procedure ให้ใส่

SET ANSI_NULLS ON
SET ANSI_WARNINGS ON
GO

http://support.microsoft.com/kb/296769

Tuesday, June 3, 2008

Replace newline to blank in .NET

For example in C#

protected void Page_Load(object sender, EventArgs e)
{
string str = "Hello \r\n world";
Response.Write(str);
Response.Write("<br/>\n");
str = str.Replace(Environment.NewLine, string.Empty);
Response.Write(str);
}

Then preview in browser and view html source.

* Environtment.NewLine is equal to \r\n

Monday, May 26, 2008

Change temporary datetime regional to SQL Server

If my database set to COLLATE Thai_CI_AS. Then, I select datetime format 106, result below

SELECT CONVERT(VARCHAR,GETDATE(),106)
Result: 26 พ.ค. 2008


If I want to select in english format, I must use command this

SET LANGUAGE us_english
SELECT CONVERT(VARCHAR,GETDATE(),106)
Result: 26 May 2008

SET LANGUAGE us_english
SELECT CONVERT(VARCHAR,GETDATE(),106)

SET LANGUAGE thai
SELECT CONVERT(VARCHAR,GETDATE(),106)


************************************************************

Case Study:
My problem, I created web application with ASP.NET and the application use datetime in format "dd-MMM-yyyy" for example "16-May-2008"(I set CultureInfo to "en-US" in Global.asax shown below).

void Application_BeginRequest(object sender, EventArgs e)
{
// Code that runs on application startup
System.Globalization.CultureInfo vNewCulture = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = vNewCulture;
}

In test environment I connected the application to SQL Server database(in same IIS). The server set regional language to "en-US". When I query data from database, result is nomally.

Then I migrate database to real database server. In the real database server set regional to Thai "th-TH". When the application query data from database server, I founded error.

I fixed this problem by insert "SET LANGUAGE us_english" at the beginning of query data to all query.

************************************************************

http://mark-dot-net.blogspot.com

How to send username and password in ftp url path

If you want to access to ftp://localhost/ with username 'myUserName' and password 'myPassword'. There are 3 method to access this ftp by explorer windows.

Method 1
Step1: Start -> run
Step2: Input ftp://localhost/
Step3: Input username and password into dialog box.
Step4: Access completed.

Method 2 Auto insert username on dialog box
Step1. Start -> run
Step2. Input ftp://myUserName@localhost/
Step3. Input only password into dialog box.
Step4: Access completed.

Method 3 Auto insert username and password in diaglog box.
Step1. Start -> run
Step2. Input ftp://myUserName:myPassword@localhost/
Step3. Access completed.

Saturday, May 24, 2008

SET ANSI_NULLS ON Example

-- Create table t1 and insert values.
CREATE TABLE t1 (a INT NULL)
INSERT INTO t1 values (NULL)
INSERT INTO t1 values (0)
INSERT INTO t1 values (1)
GO

-- Print message and perform SELECT statements.
PRINT 'Testing default setting'
DECLARE @varname int
SELECT @varname = NULL
SELECT *
FROM t1
WHERE a = @varname
SELECT *
FROM t1
WHERE a <> @varname
SELECT *
FROM t1
WHERE a IS NULL
GO

-- SET ANSI_NULLS to ON and test.
PRINT 'Testing ANSI_NULLS ON'
SET ANSI_NULLS ON
GO
DECLARE @varname int
SELECT @varname = NULL
SELECT *
FROM t1
WHERE a = @varname
SELECT *
FROM t1
WHERE a <> @varname
SELECT *
FROM t1
WHERE a IS NULL
GO

-- SET ANSI_NULLS to OFF and test.
PRINT 'Testing SET ANSI_NULLS OFF'
SET ANSI_NULLS OFF
GO
DECLARE @varname int
SELECT @varname = NULL
SELECT *
FROM t1
WHERE a = @varname
SELECT *
FROM t1
WHERE a <> @varname
SELECT *
FROM t1
WHERE a IS NULL
GO

-- Drop table t1.
DROP TABLE t1

Reference
http://msdn.microsoft.com/en-us/library/ms188048.aspx

Sunday, May 4, 2008

Bug in SQL Server 2000 when create store procedure contain linked server

When I created store procedure command contained linked server in its. I founded error message below.

Error 7405: Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent querysemantics. Enable these options and then reissue your query.

Just insert the following commands before creating/updating your store procedure or function.

SET ANSI_NULLS ON
SET ANSI_WARNINGS ON
GO
CREATE FUNCTION dbo.functionName
...
END

References
http://support.microsoft.com/kb/296769
http://www.nophadon.com/2004/03/18/error-7405-heterogeneous-queries-sql-server-2/

Get current datetime

SQL Server:
SELECT GETDATE()

SELECT {fn NOW()}

SELECT CURRENT_TIMESTAMP


Oracle:
SELECT SYSDATE AS Now FROM dual;

SELECT CURRENT_DATE AS Now FROM dual;


Reference
http://msdn2.microsoft.com/en-us/library/ms187928.aspx
http://www.psoug.org/reference/date_func.html

Command for describe table

SQL Server

Syntax:
SP_HELP <tablename>

SP_COLUMNS <tablename>


Oracle
Describe an Oracle Table, View, Synonym, package or Function.
Note: that because this is a SQL*Plus command you don't need to terminate it with a semicolon.

Syntax:
DESC table

DESC view

DESC synonym

DESC function

DESC package