Friday, December 04, 2009

SQL Server @@ROWCOUNT returns 1 if Min Max used in query

Hi,

I came across this crazy issue today. You expect @@Rowcount to return number of rows returned by query right. But in my case it was returning 1 for 0 rows returned.
Here is an example.

SELECT *
FROM yourtable WHERE 1 = 2

SELECT @@ROWCOUNT -- THIS GIVES 0

But if you have MIN function being used, the result will be different

declare @company_id int

SELECT @company_id = min(company_id)
FROM yourtable WHERE 1 = 2

SELECT @@ROWCOUNT -- THIS GIVES 1

Apparently, since NULL was the result set, @@rowcount was giving 1 as the count.

I hope this helps someone.

Thursday, October 29, 2009

SQL Server Insert Into Identity Column

We all know that if you have an identity column and if you try to insert a value in the identity column, you will get an error. Here is how you can avoid the error

First thing to do here is to set Identity to ON on the tblname you want to insert row in.

SET IDENTITY_INSERT tblname ON

INSERT tblname (ID,colname) VALUES(5,'ajas')

SET IDENTITY_INSERT tblname OFF

Do not forget to set IDENTITY_INSERT to off once you are done with inserting the record because you dont want it to be off if you have an application where developers will be working on it.

Hope this Helps.

Tuesday, October 27, 2009

RDP End a Disconnected session

We all have had issues where in a RDP disconnected session wont allow other users to login until the administrator manually kills that disconnected session. Well, I just found out that there is a setting in Windows Server 2003 which would allow to automatically kill a RDP Disconnected session.

Go to Start - Administrative Tools - Terminal Services Configuration.

In Terminal Services Configuration, select Connections - RDP-Tcp. Right click RDP-Tcp and select properties. Go to sessions tab and select override user settings which is disabled by default. Here is a snapshot of the setting.



Many thanks to Cameron Childress for this post titled
How to Automatically Log Off Disconnected Remote Desktop / Terminal Services Sessions


This article is also good.

Tuesday, September 22, 2009

Lets Fifa - Fifa 10 Demo Trailer

Its that time of the year again. Yes, Fifa 10 demo is available for download.

Here are some videos of previews. Enjoy!!!

Awesome trailer





Monday, August 31, 2009

SQL Server Hidden Gems Perhaps

If you ever wanted to get name of all the databases on your server, you can use this query

In SQL Server 2000, select name from master..sysdatabases

In SQL Server 2005, select name from sys.databases

:-)

Sunday, August 30, 2009

ColdFusion CFID CFTOKEN Get lastvisit timecreated from CGLOBAL

I had a recent need to get information of CFID & CFTOKEN to see how many records we have in our datasource for CDATA, CGLOBAL and also from which date i.e. Last Min date to Last Max date the CGLOBAL table has values for. So I wrote this short query and then finally i cast the column as datetime so we can sort by date otherwise the sort will occur by string.

select cast( substring(data, charindex('ts',data) + 4 , 19) as datetime) as 'lastvisit' ,
cast( substring(data, charindex('ts',data,charindex('ts',data)+4 ) + 4 , 19) as datetime) as 'timecreated', lvisit from cglobal

where charindex('ts',data) gets the first occurrence and len('2009-08-18 22:36:55') gives you an idea of how many characters you need to extract and turns out its 19 characters.

Link to how ColdFusion Purges Client Variables

Hope this helps someone.

Wednesday, August 26, 2009

ColdFusion Optimization Performance tuning

Nice articles for ColdFusion Optimization and performance tuning.

Adobe link for performance and scalability

ColdFusion Tips For troubleshooting by Steve Erat

ColdFusion Request Tuning Settings in Depth

ColdFusion Tips For troubleshooting by Steve Erat Part 2

Nice post by Mark Kruger

Sick Server Troubleshooting Part 2 - Things to Try

Sick Server Troubleshooting Part 3 - In the Soup


About Java Memory Management


Toward Better CF Server Administration Part 1 of 2


Toward Better CF Server Administration Part 2 of 3


Updated on Mon Aug 31. From Ben Forta's book, Understanding Java Stack Traces From Exception.log


To Be Continued...

SQL Server Hidden Gem - How to get next value of Identity for a column in a table

Hi,

This is very nice tip if you ever wanted to find the next value of identity column without doing an insert, I repeat without doing an Insert.

Lets say you have a table named company. Then you would use this command

SELECT IDENT_CURRENT('company') + IDENT_INCR('company')

where IDENT_CURRENT gives the current or last identity value used by that table and IDENT_INCR gives the increment you/anyone had set during creation of table. It could 1, 2 etc depending on your logic.

The other way of finding next value of identity is after an insert statement by using SCOPE_IDENTITY(). You would add 1 or 2 and so on depending on the autoincrement setting you used during the table creation.

Hope this helps.