Tuesday, September 30, 2008

How to dynamically number rows in a SELECT Transact-SQL statement

Reference URL: http://support.microsoft.com/kb/186133

If you have to return a single record set while joining any tables, than first create a view and then apply:

Use the following code in SQL Server 2005.

select rank() OVER (ORDER BY a.au_lname, a.au_fname) as rank, a.au_lname, a.au_fname
from authors a order by rank

Use the following code in SQL Server 2000.

select rank=count(*), a1.au_lname, a1.au_fname
from authors a1, authors a2
where a1.au_lname + a1.au_fname >= a2.au_lname + a2.au_fname
group by a1.au_lname, a1.au_fname
order by rank


You can get more details by typing "dynamically number rows site:support.microsoft.com" in google search box.

Friday, September 5, 2008

Manually configure SQL Express and the Windows Firewall to allow remote access.

Manually configure SQL Express and the Windows Firewall to allow remote access. Use the following steps to enable remote access to SQL Express:

1. Open the SQL Server Configuration Manager by clicking Start, All Programs, Microsoft SQL Server 2005, Configuration Tools, SQL Server Configuration Manager.
2. In the left pane of the SQL Server Configuration Manger, expand the node for SQL Server 2005 Network Configuration and select Protocols for SQLEXPRESS.
3. In the right pane, right-click Named Pipes and choose Enable.
4. Right-click TCIP/IP and choose Enable.
5. In the left pane, select SQL Server 2005 Services.
6. In the right pane, right-click SQL Server Browser and choose Properties.
7. Click the Services tab in the Properties dialog box.
8. On the Services page, set the Start Mode property to Automatic and click OK.
9. Right-click SQL Server Browser and choose Start.
10. Right click SQL Server (SQLEXPRESS) and choose Restart.

Use the following steps to configure the Windows firewall.

1. Open the Windows Firewall dialog box and click the Exceptions tab.
2. Click Add Program and Browse to find sqlbrowser.exe and click OK.
3. Click Add Program and Browse to find sqlservr.exe. Click OK.
4. Click Add Port and enter ?�SQL Service??for Name, 1433 for Port number, and select the TCP radio button.
5. Click OK on the Windows Firewall dialog

Thursday, September 4, 2008

Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances

If you are getting the following error:

“Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances” What should I do?

Answer: To fix this, please Open the SQL Server Management Studio Express. This is the downloadable program in the same site where you downloaded the SQL Server 2005 express used to manage SQL Server 2005 Express.


In the query editor type this text: exec sp_configure 'user instances enabled', 1.


Then type: Reconfigure.


Then restart the SQL Server database.


Ref: http://blogs.msdn.com/hongmeig/archive/2007/08/31/generating-user-instances-in-sql-server-is-disabled-use-sp-configure-user-instances-enabled-to-generate-user-instances.aspx