GoDaddy Website Builder for $1/Mo.!

Adbrite

Tuesday, December 7, 2010

T-SQL Debugging – Error

SQL Server Debugging/Microsoft SQL Server Management Studio – Error

Last two month I have spent most of time to Debugging T-SQL code. Some certain situation I have noticed T-SQL Debugging given errors. When I’m working only my own SQL server instance, it’s (T-SQL Debugging) working without any problem. But when I’m connected different server and execute procedures with T-SQL Debugging then it will gives me following error,

Unable to start T-SQL debugging. Could not attach to SQL Server process on ’YOUR SERVER’ .click help for more information.

I have work with T-SQL debugging many times but first time I have notice above error. I try to find some information about this error, but I could not found good relative information. Finally I have decided compare my server configuration with error given server instance configuration. Microsoft categorizes most of above errors under [configuration problem]/ [security problem]. So my security comparison gives me the answer for above error.

The problem is I have working under domain account. I connected in above error given server instance using “SA“ user, the problem is “SA” user cannot execute above server T-SQL debugger. In that case I have created my domain account login to above error given SQL server instance.

CREATE LOGIN [DOMAIN\login name] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]

GO

Great now it’s working. If anyone have above T-SQL Debugging error hope this post will help you!!!

Friday, November 12, 2010

ISDATE Function doesn’t validate “date” and “datetime2” data types

Last week I have done some R&D stuff reading SQL Server and as well as Oracle. Recently I have come up with issue how to validate Date column. Answer is very simple; Every SQL Server guy’s Answer is ISDATE function and my answer was same. But after few second, again have a complained we can’t use this function it gives error. I got surprised and ask him to send that error with table format,
  • Column data type is – date (SQL Server 2008)
  • Error,
Msg 8116, Level 16, State 1, Line 3
Argument data type date is invalid for argument 1 of isdate function.

Then I have created some sample T-SQL scripts and check the issue.

USE tempdb
GO
DECLARE @smalldatetime smalldatetime
SELECT @smalldatetime='01/01/2010'
SELECT ISDATE(@smalldatetime);
GO
DECLARE @date date
SELECT @date='01/01/2010'
SELECT ISDATE(@date); --Error
GO
DECLARE @datetime datetime
SELECT @datetime='01/01/2010'
SELECT ISDATE(@datetime);
GO
DECLARE @datetime2 datetime2
SELECT @datetime2='01/01/2010'
SELECT ISDATE(@datetime2); --Error
GO

Finally I realize the problem ISDATE function, only working datetime, smalldatetime data types. Funny thing is Microsoft did not update the ISDATE () function to support this data types. Even it’s not supported SQL SERVER 2008 R2. Simply it doesn’t validate “date” data type and “datetime2” data type. After checking details for this issue Microsoft promised to consider this in there next release (I didn’t check this issue using SQL Server new CTP1 release (”Denali”))

Saturday, October 16, 2010

Some doubt about integer (INT) data type columns

Some doubt about integer (INT) data type columns

Recently I have some doubt about integer (INT) data type column. Let me explain this doubtful problem, if you insert or update blank records to integer column it will update as 0.But if it is decimal data type situation bit different. Check following example,

use tempdb
go
drop table T1
go
create table T1(col1 int primary key
,col2 tinyint
,col3 smallint
,col4 int
,col5 bigint
,col6 decimal(9,1)
,col7 varchar(5));
go
select * from T1
go
begin tran
insert into T1 select 1,11,111,1111,11111,111111,'R1'
insert into T1 select '','','','','',-1,''
commit tran
go
select * from T1
go

If you try following example then you may come up with this error,

begin tran
insert into T1 select 1,11,111,1111,11111,111111,'R1'
insert into T1 select '','','','','','','' --error
insert into T1 select ' ',' ',' ',' ',' ',' ',' ' --error
commit tran

Result,
Server: Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric.

Finally I come up with some conclusion but I have some doubt when we dealing with decimal data type. MSSQL consider blank value as 0 if you use only integer data type but if you dealing with string data type(varchar) it will remain as same. I will try to find more information about decimal data type and update it in future
post.

Saturday, February 13, 2010

How to add WHERE clause after execute procedure returns values?

Let me start like this “Do we have any mechanism to add WHERE clause after execute procedure returns values?” Answer is YES but we need to spend bit time. But recently I found smart Answer for above Question.i will explain here my old concept and new concept,

Old concept,

USE AdventureWorks2008
GO
--create table
CREATE TABLE MyRecords
(col1 int,
col2 varchar(25)
);
GO

--insert Records
INSERT INTO MyRecords
SELECT TOP 15 [object_id],[name]
FROM sys.objects
WHERE (LEN([name]) BETWEEN 0 AND 25)
/* cannot add less-then sign because of html validation */
ORDER BY
[object_id];

GO

--create procedure
CREATE PROCEDURE proc_get_records
AS
SET NOCOUNT ON
SELECT col1 [object_id], col2 [name] FROM MyRecords;
SET NOCOUNT OFF
GO

--execute sp
EXEC proc_get_records; --this will returns 15 rows
GO

If you need to check your procedure returns values contain some specific value, then you have to do following mechanism.


--if we need to check procedure returns value contain object id 7
CREATE TABLE #tempTable
(col1 int,
col2 varchar(25)
);

INSERT INTO #tempTable
EXEC proc_get_records;

SELECT * FROM #tempTable WHERE (col1=7);
GO

New concept,

Now you can realize above method very effective but time consuming work.Let’s say your procedure contains many columns with different data types and finally it will returns more than thousand rows. Then no doubt this will be, bit time consuming processes. And sometimes your Production Database environment does not allow you to create temp tables or you might be haven’t any permission to create tables. Then this will be painful problem.This is how you can sort-out above Problem,This is very smart concept I found recently when I’m go through OPENDATASOURCE and OPENROWSET functions.And pls Notice,i`m using same table formats I have created earlier to explain this,

USE AdventureWorks2008
GO
EXEC proc_get_records;
GO
SELECT *
FROM OPENROWSET('SQLOLEDB',
'Server=THARINDU\SQLDEV2008;Trusted_Connection=yes;',
'EXEC AdventureWorks2008.dbo.proc_get_records')
WHERE ([object_id] IN(5,3,7))
ORDER BY [object_id];


Still I couldn’t found good mechanism to do same concept using oracle. Any way I’ll try and Update my blog in future post.