Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Sunday, March 11, 2012

Bug in SSIS?

I am trying to convert a string to a specific date format by using a simple select like this:

SELECT CONVERT(VARCHAR(3), CONVERT(DATETIME, ?, 103),107)

First of all the Parameter ? is not recognized and when i run the Preview it would trought the following error even if i change the ? with '20050101' for example:

===================================

There was an error displaying the preview. (Microsoft Visual Studio)

===================================

Undefined function 'CONVERT' in expression. (Microsoft JET Database Engine)


Program Location:

at Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask.Connections.SQLTaskConnectionOleDbClass.ExecuteStatement(Int32 resultType, Boolean isStoredProc, UInt32 dwTimeOut)
at Microsoft.DataTransformationServices.Design.PipelineUtils.ShowDataPreview(String sqlStatement, ConnectionManager connectionManager, Control parentWindow, IServiceProvider serviceProvider, IDTSExternalMetadataColumnCollection90 externalColumns)
at Microsoft.DataTransformationServices.DataFlowUI.DataFlowConnectionPage.previewButton_Click(Object sender, EventArgs e)

Anyone experiencing this kind of problem? Solutions?

Best Regards,

Luis Sim?es

Well the error clearly indicates that Jet doesn't support the function so this would not be an SSIS bug. Have you attempted to look at the Jet docs to see if it supports convert. The last time I used jet it did not.

Thanks,

Matt

|||

Yes you are right.

I have figured it out pretty quickly and i tried to delete this post without success sorry...

It was my mistake! Not really looking into it :P

But thanks :)

Best Regards,

PS: Merry Christmas to All of YOU!

Bug in SQL SERVER 2005

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

-- =============================================

-- Author: Suyog Dabhole

-- Create date: 19-9-2007

=============================================

ALTER PROCEDURE [dbo].[procGetAllMinibarStatus]

@.AllRooms bit=1, --true if user wants to search for all rooms,false if user does not want to search

@.SingleRoom nvarchar(10)=NULL, --User sends RoomNumber otherwise null

@.ByGroup nvarchar(20)=NULL, --User sends Group name otherwise null

@.ByAreaFrom nvarchar(10)=NULL, --User sends ByAreaFrom otherwise null

@.ByAreaTo nvarchar(10)=NULL, --User sends ByAreaTo otherwise null

@.LockUnlockStatus nvarchar(10)=NULL,

@.CoolerStatus nvarchar(10)=NULL,

@.MinibarStatus nvarchar(10)=NULL,

@.CommunicationStatus nvarchar(10)=NULL

AS

BEGIN

SET NOCOUNT ON;

DECLARE @.strBasicQuery nvarchar(MAX)

SET @.strBasicQuery='SELECT tblRooms.RoomNumber, tblRooms.RoomStatus,

tblMinibars.MinibarDisplayName,

tblModelGrids.ModelGridName,

tblMinibars.MinibarLockStatus,

CASE WHEN tblMinibars.MinibarLockStatus = ''true'' THEN ''~\Images\LockStatusLOCK.gif'' ELSE ''~\Images\LockStatusUNLOCK.gif'' END AS ''MinibarLockStatusImagePath'',

tblMinibars.MinibarCoolerStatus,

CASE WHEN tblMinibars.MinibarCoolerStatus = ''true'' THEN ''MinibarCoolerStatusON.gif'' ELSE ''MinibarCoolerStatusOFF.gif'' END AS ''MinibarCoolerStatusImagePath'',

tblMinibars.MinibarModeStatus, tblMinibars.MinibarOfflineStatus,

CASE WHEN tblMinibars.MinibarOfflineStatus = ''true'' THEN ''OfflineStatusON.gif'' ELSE ''C:\OfflineStatusOFF.gif'' END AS ''MinibarOfflineStatusImagePath'',

tblMinibars.MinibarCoolingStatus,

CASE WHEN tblMinibars.MinibarCoolingStatus = ''true'' THEN ''CoolingStatusAlarmON.gif'' ELSE ''CoolingStatusAlarmOFF.gif'' END AS ''MinibarCoolingStatusImagePath'',

tblMinibars.MinibarDoorOpenStatus,

CASE WHEN tblMinibars.MinibarDoorOpenStatus = ''true'' THEN ''DoorOpenStatus.gif'' ELSE ''DoorOpenStatusOFF.gif'' END AS ''MinibarDoorOpenStatusImagePath'',

tblMinibars.MinibarTooManyDoorOpening,

CASE WHEN tblMinibars.MinibarTooManyDoorOpening = ''true'' THEN ''TooManyDoorOpeningON.gif'' ELSE ''TooManyDoorOpeningOFF.gif'' END AS ''MinibarTooManyDoorOpeningImagePath'',

tblMinibars.MinibarCourtesyXStatus,

CASE WHEN tblMinibars.MinibarCourtesyXStatus = ''true'' THEN ''CourtesyXStatusON.gif'' ELSE ''CourtesyXStatusOFF.gif'' END AS ''MinibarCourtesyXStatusImagePath'',

tblMinibars.MinibarID, tblMinibars.RoomID

FROM tblMinibars INNER JOIN

tblRooms ON tblMinibars.RoomID = tblRooms.RoomID AND tblRooms.IsDeleted = 0 INNER JOIN

tblModelGrids ON tblMinibars.GridID = tblModelGrids.GridID '

IF(@.AllRooms =1)

BEGIN

IF(@.LockUnlockStatus IS NOT NULL or @.CoolerStatus IS NOT NULL or @.MinibarStatus IS NOT NULL or @.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE '

END

END

ELSE IF(@.SingleRoom IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE tblRooms.RoomID=(select DISTINCT RoomID from tblRooms where RoomNumber=@.SingleRoom and IsDeleted=0) and tblRooms.RoomStatus=@.RoomStatus'+' and '

END

ELSE IF(@.ByGroup IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE tblRooms.RoomID IN (SELECT RoomID FROM tblRoomGroups WHERE GroupID=(SELECT DISTINCT GroupID FROM tblGroups WHERE GroupName=@.ByGroup and IsDeleted=0)) and tblRooms.RoomStatus=@.RoomStatus and tblRooms.IsDeleted=0'+' and '

END

ELSE IF((@.ByAreaFrom IS NOT NULL) AND (@.ByAreaTo IS NOT NULL) )

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE tblRooms.RoomID IN (SELECT DISTINCT RoomID FROM tblRooms WHERE RoomNumber>=@.ByAreaFrom AND RoomNumber<=@.ByAreaTo ) and tblRooms.RoomStatus=@.RoomStatus'+' and '

END

IF(@.LockUnlockStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarLockStatus='''+@.LockUnlockStatus+''''

IF(@.CoolerStatus IS NOT NULL or @.MinibarStatus IS NOT NULL or @.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+N' and '

END

END

IF(@.CoolerStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarCoolerStatus='''+@.CoolerStatus+''''

IF(@.MinibarStatus IS NOT NULL or @.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+N' and '

END

END

IF(@.MinibarStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarModeStatus='''+@.MinibarStatus+''''

IF(@.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+N' and '

END

END

IF(@.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarOfflineStatus='''+@.CommunicationStatus+''''

END

RETURN @.strBasicQuery

EXEC (@.strBasicQuery)

SET NOCOUNT OFF

END

I am getting following error

Msg 245, Level 16, State 1, Procedure procGetAllMinibarStatus, Line 104

Conversion failed when converting the nvarchar value 'SELECT tblRooms.RoomNumber, tblRooms.RoomStatus,

tblMinibars.MinibarDisplayName,

tblModelGrids.ModelGridName,

tblMinibars.MinibarLockStatus,

CASE WHEN tblMinibars.MinibarLockStatus = 'true' THEN '~\Images\LockStatusLOCK.gif' ELSE '~\Images\LockStatusUNLOCK.gif' END AS 'MinibarLockStatusImagePath',

tblMinibars.MinibarCoolerStatus,

CASE WHEN tblMinibars.MinibarCoolerStatus = 'true' THEN 'MinibarCoolerStatusON.gif' ELSE 'MinibarCoolerStatusOFF.gif' END AS 'MinibarCoolerStatusImagePath',

tblMinibars.MinibarModeStatus, tblMinibars.MinibarOfflineStatus,

CASE WHEN tblMinibars.MinibarOfflineStatus = 'true' THEN 'OfflineStatusON.gif' ELSE 'C:\OfflineStatusOFF.gif' END AS 'MinibarOfflineStatusImagePath',

tblMinibars.MinibarCoolingStatus,

CASE WHEN tblMinibars.MinibarCoolingStatus = 'true' THEN 'CoolingStatusAlarmON.gif' ELSE 'CoolingStatusAlarmOFF.gif' END AS 'MinibarCoolingStatusImagePath',

tblMinibars.MinibarDoorOpenStatus,

CASE WHEN tblMinibars.MinibarDoorOpenStatus = 'true' THEN 'DoorOpenStatus.gif' ELSE 'DoorOpenStatusOFF.gif' END AS 'MinibarDoorOpenStatusImagePath',

tblMinibars.MinibarTooManyDoorOpening,

CASE WHEN tblMinibars.MinibarTooManyDoorOpening = 'true' THEN 'TooManyDoorOpeningON.gif' ELSE 'TooManyDoorOpeningOFF.gif' END AS 'MinibarTooManyDoorOpeningImagePath',

tblMinibars.MinibarCourtesyXStatus,

CASE WHEN tblMinibars.MinibarCourtesyXStatus = 'true' THEN 'CourtesyXStatusON.gif' ELSE 'CourtesyXStatusOFF.gif' END AS 'MinibarCourtesyXStatusImagePath',

tblMinibars.MinibarID, tblMinibars.RoomID

FROM tblMinibars INNER JOIN

tblRooms ON tblMinibars.RoomID = tblRooms.RoomID AND tblRooms.IsDeleted = 0 INNER JOIN

tblModelGrids ON tblMinibars.GridID = tblModelGrids.GridID WHERE tblRooms.RoomID=(select DISTINCT RoomID from tblRooms where RoomNumber=@.SingleRoom and IsDele... <-- What is mean by this?

1) how to increase the size of nvarchar(MAX)

2)I am returning strBasicQuery for purpose of it's value.Here issuse is my query character's extending limit of nvarchar(MAX)

Kindly provide solution for me ASAP

The problem is the RETURN statement. Return is the command to exit the procedure and return an exitcode. The exitcode is defined as INT. So, it's natural that your return command generates the error because the system cannot convert @.strBasicQuery to INT.

Instead of using RETURN @.strBasicQuery, you'd do "print @.strBasicQuery".

|||

Quickest way to increase the size of nvarchar(max) is to use varchar(max). I don't seen any UNICODE characters in your query, so use VarChar. that will DOUBLE the number of characters you can use.

varchar(max) is two times the characters of nvarchar(max)

If you must use nvarchar (we have a lot of kanji stuff for example) you'll have to break it up into muliple queries, sorta like this:

Code Snippet

Create Table #Temp(SomeField int)

declare @.cmd nvarchar(max)

set @.cmd = 'insert into #Temp select 1'

exec(@.cmd)

set @.cmd = 'insert into #Temp select 2'

exec (@.cmd)

select * from #temp

|||

>>Quickest way to increase the size of nvarchar(max) is to use varchar(max). I don't seen any UNICODE characters in your query, so use VarChar. that will DOUBLE the number of characters you can use. <<

nvarchar(max) will hold like a billion characters, which is clearly not being taxed. The problem is, as OJ states, that he is trying to return a character, when RETURN in a stored procedure may only return an integer value

|||

problem is not returning values

kindly see error(end section with red color)

What is mean by IsDeleted...<

I am returning @.strBasicQuery for showing you that finally when i run exec(@.strBasicQuery)

it will not execute because my @.strBasicQuery's final value is end like IsDeleted... which is incomplete.

Kindly see error it showing value of @.strBasicQuery

i know that i have to return int not string

kindly provide solution ASAP

|||

problem is not returning values

kindly see error(end section with red color)

What is mean by IsDeleted...<

I am returning @.strBasicQuery for showing you that finally when i run exec(@.strBasicQuery)

it will not execute because my @.strBasicQuery's final value is end like IsDeleted... which is incomplete.

Kindly see error it showing value of @.strBasicQuery

i know that i have to return int not string

kindly provide solution ASAP

|||

problem is not returning values

kindly see error(end section with red color)

What is mean by IsDeleted...<

I am returning @.strBasicQuery for showing you that finally when i run exec(@.strBasicQuery)

it will not execute because my @.strBasicQuery's final value is end like IsDeleted... which is incomplete.

Kindly see error it showing value of @.strBasicQuery

i know that i have to return int not string

kindly provide solution ASAP

|||

The key to this error is: Conversion failed when converting the nvarchar value and i believe it would finish with to datatype int. This is because RETURN expects and integer value as suggested earlier.

However, I wonder if the reason the string is truncated is due to a limitation in the error handling of SQL. I don't think its anything to do with your SQL string being truncated. To test, comment out your EXEC statement and follow the guys advice previously and change:


RETURN @.strBasicQuery

to be:

PRINT @.strBasicQuery

This will give you the SQL String you are trying to execute.

HTH!

|||First, RETURN is expecting an int. You cannot return a string. Change RETURN to PRINT.

Second, the "IsDeleted..." is not your problem. The error message only displays the first 1024 characters of the command.

Third, your real problem is the EXEC command does not access varchar(max), yes I know it says it does, it but doesn't. You need to break your command into multiple varchar(4000) strings and add them together into an EXEC. Like this:

DECLARE @.sql1 varchar(4000), @.sql2 varchar(4000), @.sql3 varchar(4000)

SET @.sql1 = 'SELECT *'
SET @.sql2 = ' FROM TABLEA'
SET @.sql3 = ' WHERE A=A'

EXEC (@.sql1+@.sql2+@.sql3)

|||

Tom Phillips wrote:


Third, your real problem is the EXEC command does not access varchar(max), yes I know it says it does, it but doesn't. You need to break your command into multiple varchar(4000) strings and add them together into an EXEC. Like this:

Tom, that is not correct. Execute can work with varchar(max) just fine. Here is an example for you.

Code Snippet

declare @.var1 varchar(8000), @.var2 varchar(8000), @.sql varchar(max)

set @.var1 = replicate('A',8000)
set @.var2 = replicate('B',8000)
set @.sql = 'select len(''' + cast(@.var1 as varchar(max)) + cast(@.var2 as varchar(max)) + ''')'

exec(@.sql)

|||

Suyog, the problem is the RETURN. Again, you cannot return a string, only INT.

The reason you see the last word "IsDeleted" is because the error message is truncated. It's by no mean cause in this case.

Here is a quick example to stress the point.

Code Snippet

create proc bad
as
declare @.ret varchar(max)
set @.ret = 'I am a string'
return @.ret
go

create proc good
as
declare @.ret int
set @.ret = 999
return @.ret
go

--this will never work!

declare @.return varchar(max)
exec @.return=bad
select @.return [bad]
go

declare @.return int
exec @.return=good
select @.return [good]
go

drop proc bad,good
go

|||oj,

I keep hearing that, and your code works. However, every time I try it in production, it fails. I don't know what the cause is, except if I change it to multiple varchars, instead of varchar(max), it works fine.

|||

Tom Phillips wrote:

oj,

I keep hearing that, and your code works. However, every time I try it in production, it fails. I don't know what the cause is, except if I change it to multiple varchars, instead of varchar(max), it works fine.

You're more than likely hitting "data type precedence" issue.

Let's take a look at previous example, if I forget to convert() to varchar(max), my example would be failing too.

Code Snippet

declare @.var1 varchar(8000), @.var2 varchar(8000), @.sql varchar(max)

set @.var1 = replicate('A',8000)
set @.var2 = replicate('B',8000)
set @.sql = 'select len(''' + @.var1 + @.var2 + ''')'

exec(@.sql)

More info on data type precedence:

http://msdn2.microsoft.com/en-us/library/ms190309.aspx

Bug in SQL SERVER 2005

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

-- =============================================

-- Author: Suyog Dabhole

-- Create date: 19-9-2007

=============================================

ALTER PROCEDURE [dbo].[procGetAllMinibarStatus]

@.AllRooms bit=1, --true if user wants to search for all rooms,false if user does not want to search

@.SingleRoom nvarchar(10)=NULL, --User sends RoomNumber otherwise null

@.ByGroup nvarchar(20)=NULL, --User sends Group name otherwise null

@.ByAreaFrom nvarchar(10)=NULL, --User sends ByAreaFrom otherwise null

@.ByAreaTo nvarchar(10)=NULL, --User sends ByAreaTo otherwise null

@.LockUnlockStatus nvarchar(10)=NULL,

@.CoolerStatus nvarchar(10)=NULL,

@.MinibarStatus nvarchar(10)=NULL,

@.CommunicationStatus nvarchar(10)=NULL

AS

BEGIN

SET NOCOUNT ON;

DECLARE @.strBasicQuery nvarchar(MAX)

SET @.strBasicQuery='SELECT tblRooms.RoomNumber, tblRooms.RoomStatus,

tblMinibars.MinibarDisplayName,

tblModelGrids.ModelGridName,

tblMinibars.MinibarLockStatus,

CASE WHEN tblMinibars.MinibarLockStatus = ''true'' THEN ''~\Images\LockStatusLOCK.gif'' ELSE ''~\Images\LockStatusUNLOCK.gif'' END AS ''MinibarLockStatusImagePath'',

tblMinibars.MinibarCoolerStatus,

CASE WHEN tblMinibars.MinibarCoolerStatus = ''true'' THEN ''MinibarCoolerStatusON.gif'' ELSE ''MinibarCoolerStatusOFF.gif'' END AS ''MinibarCoolerStatusImagePath'',

tblMinibars.MinibarModeStatus, tblMinibars.MinibarOfflineStatus,

CASE WHEN tblMinibars.MinibarOfflineStatus = ''true'' THEN ''OfflineStatusON.gif'' ELSE ''C:\OfflineStatusOFF.gif'' END AS ''MinibarOfflineStatusImagePath'',

tblMinibars.MinibarCoolingStatus,

CASE WHEN tblMinibars.MinibarCoolingStatus = ''true'' THEN ''CoolingStatusAlarmON.gif'' ELSE ''CoolingStatusAlarmOFF.gif'' END AS ''MinibarCoolingStatusImagePath'',

tblMinibars.MinibarDoorOpenStatus,

CASE WHEN tblMinibars.MinibarDoorOpenStatus = ''true'' THEN ''DoorOpenStatus.gif'' ELSE ''DoorOpenStatusOFF.gif'' END AS ''MinibarDoorOpenStatusImagePath'',

tblMinibars.MinibarTooManyDoorOpening,

CASE WHEN tblMinibars.MinibarTooManyDoorOpening = ''true'' THEN ''TooManyDoorOpeningON.gif'' ELSE ''TooManyDoorOpeningOFF.gif'' END AS ''MinibarTooManyDoorOpeningImagePath'',

tblMinibars.MinibarCourtesyXStatus,

CASE WHEN tblMinibars.MinibarCourtesyXStatus = ''true'' THEN ''CourtesyXStatusON.gif'' ELSE ''CourtesyXStatusOFF.gif'' END AS ''MinibarCourtesyXStatusImagePath'',

tblMinibars.MinibarID, tblMinibars.RoomID

FROM tblMinibars INNER JOIN

tblRooms ON tblMinibars.RoomID = tblRooms.RoomID AND tblRooms.IsDeleted = 0 INNER JOIN

tblModelGrids ON tblMinibars.GridID = tblModelGrids.GridID '

IF(@.AllRooms =1)

BEGIN

IF(@.LockUnlockStatus IS NOT NULL or @.CoolerStatus IS NOT NULL or @.MinibarStatus IS NOT NULL or @.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE '

END

END

ELSE IF(@.SingleRoom IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE tblRooms.RoomID=(select DISTINCT RoomID from tblRooms where RoomNumber=@.SingleRoom and IsDeleted=0) and tblRooms.RoomStatus=@.RoomStatus'+' and '

END

ELSE IF(@.ByGroup IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE tblRooms.RoomID IN (SELECT RoomID FROM tblRoomGroups WHERE GroupID=(SELECT DISTINCT GroupID FROM tblGroups WHERE GroupName=@.ByGroup and IsDeleted=0)) and tblRooms.RoomStatus=@.RoomStatus and tblRooms.IsDeleted=0'+' and '

END

ELSE IF((@.ByAreaFrom IS NOT NULL) AND (@.ByAreaTo IS NOT NULL) )

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE tblRooms.RoomID IN (SELECT DISTINCT RoomID FROM tblRooms WHERE RoomNumber>=@.ByAreaFrom AND RoomNumber<=@.ByAreaTo ) and tblRooms.RoomStatus=@.RoomStatus'+' and '

END

IF(@.LockUnlockStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarLockStatus='''+@.LockUnlockStatus+''''

IF(@.CoolerStatus IS NOT NULL or @.MinibarStatus IS NOT NULL or @.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+N' and '

END

END

IF(@.CoolerStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarCoolerStatus='''+@.CoolerStatus+''''

IF(@.MinibarStatus IS NOT NULL or @.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+N' and '

END

END

IF(@.MinibarStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarModeStatus='''+@.MinibarStatus+''''

IF(@.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+N' and '

END

END

IF(@.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarOfflineStatus='''+@.CommunicationStatus+''''

END

RETURN @.strBasicQuery

EXEC (@.strBasicQuery)

SET NOCOUNT OFF

END

I am getting following error

Msg 245, Level 16, State 1, Procedure procGetAllMinibarStatus, Line 104

Conversion failed when converting the nvarchar value 'SELECT tblRooms.RoomNumber, tblRooms.RoomStatus,

tblMinibars.MinibarDisplayName,

tblModelGrids.ModelGridName,

tblMinibars.MinibarLockStatus,

CASE WHEN tblMinibars.MinibarLockStatus = 'true' THEN '~\Images\LockStatusLOCK.gif' ELSE '~\Images\LockStatusUNLOCK.gif' END AS 'MinibarLockStatusImagePath',

tblMinibars.MinibarCoolerStatus,

CASE WHEN tblMinibars.MinibarCoolerStatus = 'true' THEN 'MinibarCoolerStatusON.gif' ELSE 'MinibarCoolerStatusOFF.gif' END AS 'MinibarCoolerStatusImagePath',

tblMinibars.MinibarModeStatus, tblMinibars.MinibarOfflineStatus,

CASE WHEN tblMinibars.MinibarOfflineStatus = 'true' THEN 'OfflineStatusON.gif' ELSE 'C:\OfflineStatusOFF.gif' END AS 'MinibarOfflineStatusImagePath',

tblMinibars.MinibarCoolingStatus,

CASE WHEN tblMinibars.MinibarCoolingStatus = 'true' THEN 'CoolingStatusAlarmON.gif' ELSE 'CoolingStatusAlarmOFF.gif' END AS 'MinibarCoolingStatusImagePath',

tblMinibars.MinibarDoorOpenStatus,

CASE WHEN tblMinibars.MinibarDoorOpenStatus = 'true' THEN 'DoorOpenStatus.gif' ELSE 'DoorOpenStatusOFF.gif' END AS 'MinibarDoorOpenStatusImagePath',

tblMinibars.MinibarTooManyDoorOpening,

CASE WHEN tblMinibars.MinibarTooManyDoorOpening = 'true' THEN 'TooManyDoorOpeningON.gif' ELSE 'TooManyDoorOpeningOFF.gif' END AS 'MinibarTooManyDoorOpeningImagePath',

tblMinibars.MinibarCourtesyXStatus,

CASE WHEN tblMinibars.MinibarCourtesyXStatus = 'true' THEN 'CourtesyXStatusON.gif' ELSE 'CourtesyXStatusOFF.gif' END AS 'MinibarCourtesyXStatusImagePath',

tblMinibars.MinibarID, tblMinibars.RoomID

FROM tblMinibars INNER JOIN

tblRooms ON tblMinibars.RoomID = tblRooms.RoomID AND tblRooms.IsDeleted = 0 INNER JOIN

tblModelGrids ON tblMinibars.GridID = tblModelGrids.GridID WHERE tblRooms.RoomID=(select DISTINCT RoomID from tblRooms where RoomNumber=@.SingleRoom and IsDele... <-- What is mean by this?

1) how to increase the size of nvarchar(MAX)

2)I am returning strBasicQuery for purpose of it's value.Here issuse is my query character's extending limit of nvarchar(MAX)

Kindly provide solution for me ASAP

The problem is the RETURN statement. Return is the command to exit the procedure and return an exitcode. The exitcode is defined as INT. So, it's natural that your return command generates the error because the system cannot convert @.strBasicQuery to INT.

Instead of using RETURN @.strBasicQuery, you'd do "print @.strBasicQuery".

|||

Quickest way to increase the size of nvarchar(max) is to use varchar(max). I don't seen any UNICODE characters in your query, so use VarChar. that will DOUBLE the number of characters you can use.

varchar(max) is two times the characters of nvarchar(max)

If you must use nvarchar (we have a lot of kanji stuff for example) you'll have to break it up into muliple queries, sorta like this:

Code Snippet

Create Table #Temp(SomeField int)

declare @.cmd nvarchar(max)

set @.cmd = 'insert into #Temp select 1'

exec(@.cmd)

set @.cmd = 'insert into #Temp select 2'

exec (@.cmd)

select * from #temp

|||

>>Quickest way to increase the size of nvarchar(max) is to use varchar(max). I don't seen any UNICODE characters in your query, so use VarChar. that will DOUBLE the number of characters you can use. <<

nvarchar(max) will hold like a billion characters, which is clearly not being taxed. The problem is, as OJ states, that he is trying to return a character, when RETURN in a stored procedure may only return an integer value

|||

problem is not returning values

kindly see error(end section with red color)

What is mean by IsDeleted...<

I am returning @.strBasicQuery for showing you that finally when i run exec(@.strBasicQuery)

it will not execute because my @.strBasicQuery's final value is end like IsDeleted... which is incomplete.

Kindly see error it showing value of @.strBasicQuery

i know that i have to return int not string

kindly provide solution ASAP

|||

problem is not returning values

kindly see error(end section with red color)

What is mean by IsDeleted...<

I am returning @.strBasicQuery for showing you that finally when i run exec(@.strBasicQuery)

it will not execute because my @.strBasicQuery's final value is end like IsDeleted... which is incomplete.

Kindly see error it showing value of @.strBasicQuery

i know that i have to return int not string

kindly provide solution ASAP

|||

problem is not returning values

kindly see error(end section with red color)

What is mean by IsDeleted...<

I am returning @.strBasicQuery for showing you that finally when i run exec(@.strBasicQuery)

it will not execute because my @.strBasicQuery's final value is end like IsDeleted... which is incomplete.

Kindly see error it showing value of @.strBasicQuery

i know that i have to return int not string

kindly provide solution ASAP

|||

The key to this error is: Conversion failed when converting the nvarchar value and i believe it would finish with to datatype int. This is because RETURN expects and integer value as suggested earlier.

However, I wonder if the reason the string is truncated is due to a limitation in the error handling of SQL. I don't think its anything to do with your SQL string being truncated. To test, comment out your EXEC statement and follow the guys advice previously and change:


RETURN @.strBasicQuery

to be:

PRINT @.strBasicQuery

This will give you the SQL String you are trying to execute.

HTH!

|||First, RETURN is expecting an int. You cannot return a string. Change RETURN to PRINT.

Second, the "IsDeleted..." is not your problem. The error message only displays the first 1024 characters of the command.

Third, your real problem is the EXEC command does not access varchar(max), yes I know it says it does, it but doesn't. You need to break your command into multiple varchar(4000) strings and add them together into an EXEC. Like this:

DECLARE @.sql1 varchar(4000), @.sql2 varchar(4000), @.sql3 varchar(4000)

SET @.sql1 = 'SELECT *'
SET @.sql2 = ' FROM TABLEA'
SET @.sql3 = ' WHERE A=A'

EXEC (@.sql1+@.sql2+@.sql3)

|||

Tom Phillips wrote:


Third, your real problem is the EXEC command does not access varchar(max), yes I know it says it does, it but doesn't. You need to break your command into multiple varchar(4000) strings and add them together into an EXEC. Like this:

Tom, that is not correct. Execute can work with varchar(max) just fine. Here is an example for you.

Code Snippet

declare @.var1 varchar(8000), @.var2 varchar(8000), @.sql varchar(max)

set @.var1 = replicate('A',8000)
set @.var2 = replicate('B',8000)
set @.sql = 'select len(''' + cast(@.var1 as varchar(max)) + cast(@.var2 as varchar(max)) + ''')'

exec(@.sql)

|||

Suyog, the problem is the RETURN. Again, you cannot return a string, only INT.

The reason you see the last word "IsDeleted" is because the error message is truncated. It's by no mean cause in this case.

Here is a quick example to stress the point.

Code Snippet

create proc bad
as
declare @.ret varchar(max)
set @.ret = 'I am a string'
return @.ret
go

create proc good
as
declare @.ret int
set @.ret = 999
return @.ret
go

--this will never work!

declare @.return varchar(max)
exec @.return=bad
select @.return [bad]
go

declare @.return int
exec @.return=good
select @.return [good]
go

drop proc bad,good
go

|||oj,

I keep hearing that, and your code works. However, every time I try it in production, it fails. I don't know what the cause is, except if I change it to multiple varchars, instead of varchar(max), it works fine.

|||

Tom Phillips wrote:

oj,

I keep hearing that, and your code works. However, every time I try it in production, it fails. I don't know what the cause is, except if I change it to multiple varchars, instead of varchar(max), it works fine.

You're more than likely hitting "data type precedence" issue.

Let's take a look at previous example, if I forget to convert() to varchar(max), my example would be failing too.

Code Snippet

declare @.var1 varchar(8000), @.var2 varchar(8000), @.sql varchar(max)

set @.var1 = replicate('A',8000)
set @.var2 = replicate('B',8000)
set @.sql = 'select len(''' + @.var1 + @.var2 + ''')'

exec(@.sql)

More info on data type precedence:

http://msdn2.microsoft.com/en-us/library/ms190309.aspx

Bug in SQL SERVER 2005

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

-- =============================================

-- Author: Suyog Dabhole

-- Create date: 19-9-2007

=============================================

ALTER PROCEDURE [dbo].[procGetAllMinibarStatus]

@.AllRooms bit=1, --true if user wants to search for all rooms,false if user does not want to search

@.SingleRoom nvarchar(10)=NULL, --User sends RoomNumber otherwise null

@.ByGroup nvarchar(20)=NULL, --User sends Group name otherwise null

@.ByAreaFrom nvarchar(10)=NULL, --User sends ByAreaFrom otherwise null

@.ByAreaTo nvarchar(10)=NULL, --User sends ByAreaTo otherwise null

@.LockUnlockStatus nvarchar(10)=NULL,

@.CoolerStatus nvarchar(10)=NULL,

@.MinibarStatus nvarchar(10)=NULL,

@.CommunicationStatus nvarchar(10)=NULL

AS

BEGIN

SET NOCOUNT ON;

DECLARE @.strBasicQuery nvarchar(MAX)

SET @.strBasicQuery='SELECT tblRooms.RoomNumber, tblRooms.RoomStatus,

tblMinibars.MinibarDisplayName,

tblModelGrids.ModelGridName,

tblMinibars.MinibarLockStatus,

CASE WHEN tblMinibars.MinibarLockStatus = ''true'' THEN ''~\Images\LockStatusLOCK.gif'' ELSE ''~\Images\LockStatusUNLOCK.gif'' END AS ''MinibarLockStatusImagePath'',

tblMinibars.MinibarCoolerStatus,

CASE WHEN tblMinibars.MinibarCoolerStatus = ''true'' THEN ''MinibarCoolerStatusON.gif'' ELSE ''MinibarCoolerStatusOFF.gif'' END AS ''MinibarCoolerStatusImagePath'',

tblMinibars.MinibarModeStatus, tblMinibars.MinibarOfflineStatus,

CASE WHEN tblMinibars.MinibarOfflineStatus = ''true'' THEN ''OfflineStatusON.gif'' ELSE ''C:\OfflineStatusOFF.gif'' END AS ''MinibarOfflineStatusImagePath'',

tblMinibars.MinibarCoolingStatus,

CASE WHEN tblMinibars.MinibarCoolingStatus = ''true'' THEN ''CoolingStatusAlarmON.gif'' ELSE ''CoolingStatusAlarmOFF.gif'' END AS ''MinibarCoolingStatusImagePath'',

tblMinibars.MinibarDoorOpenStatus,

CASE WHEN tblMinibars.MinibarDoorOpenStatus = ''true'' THEN ''DoorOpenStatus.gif'' ELSE ''DoorOpenStatusOFF.gif'' END AS ''MinibarDoorOpenStatusImagePath'',

tblMinibars.MinibarTooManyDoorOpening,

CASE WHEN tblMinibars.MinibarTooManyDoorOpening = ''true'' THEN ''TooManyDoorOpeningON.gif'' ELSE ''TooManyDoorOpeningOFF.gif'' END AS ''MinibarTooManyDoorOpeningImagePath'',

tblMinibars.MinibarCourtesyXStatus,

CASE WHEN tblMinibars.MinibarCourtesyXStatus = ''true'' THEN ''CourtesyXStatusON.gif'' ELSE ''CourtesyXStatusOFF.gif'' END AS ''MinibarCourtesyXStatusImagePath'',

tblMinibars.MinibarID, tblMinibars.RoomID

FROM tblMinibars INNER JOIN

tblRooms ON tblMinibars.RoomID = tblRooms.RoomID AND tblRooms.IsDeleted = 0 INNER JOIN

tblModelGrids ON tblMinibars.GridID = tblModelGrids.GridID '

IF(@.AllRooms =1)

BEGIN

IF(@.LockUnlockStatus IS NOT NULL or @.CoolerStatus IS NOT NULL or @.MinibarStatus IS NOT NULL or @.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE '

END

END

ELSE IF(@.SingleRoom IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE tblRooms.RoomID=(select DISTINCT RoomID from tblRooms where RoomNumber=@.SingleRoom and IsDeleted=0) and tblRooms.RoomStatus=@.RoomStatus'+' and '

END

ELSE IF(@.ByGroup IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE tblRooms.RoomID IN (SELECT RoomID FROM tblRoomGroups WHERE GroupID=(SELECT DISTINCT GroupID FROM tblGroups WHERE GroupName=@.ByGroup and IsDeleted=0)) and tblRooms.RoomStatus=@.RoomStatus and tblRooms.IsDeleted=0'+' and '

END

ELSE IF((@.ByAreaFrom IS NOT NULL) AND (@.ByAreaTo IS NOT NULL) )

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' WHERE tblRooms.RoomID IN (SELECT DISTINCT RoomID FROM tblRooms WHERE RoomNumber>=@.ByAreaFrom AND RoomNumber<=@.ByAreaTo ) and tblRooms.RoomStatus=@.RoomStatus'+' and '

END

IF(@.LockUnlockStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarLockStatus='''+@.LockUnlockStatus+''''

IF(@.CoolerStatus IS NOT NULL or @.MinibarStatus IS NOT NULL or @.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+N' and '

END

END

IF(@.CoolerStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarCoolerStatus='''+@.CoolerStatus+''''

IF(@.MinibarStatus IS NOT NULL or @.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+N' and '

END

END

IF(@.MinibarStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarModeStatus='''+@.MinibarStatus+''''

IF(@.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+N' and '

END

END

IF(@.CommunicationStatus IS NOT NULL)

BEGIN

SET @.strBasicQuery=@.strBasicQuery+' MinibarOfflineStatus='''+@.CommunicationStatus+''''

END

RETURN @.strBasicQuery

EXEC (@.strBasicQuery)

SET NOCOUNT OFF

END

I am getting following error

Msg 245, Level 16, State 1, Procedure procGetAllMinibarStatus, Line 104

Conversion failed when converting the nvarchar value 'SELECT tblRooms.RoomNumber, tblRooms.RoomStatus,

tblMinibars.MinibarDisplayName,

tblModelGrids.ModelGridName,

tblMinibars.MinibarLockStatus,

CASE WHEN tblMinibars.MinibarLockStatus = 'true' THEN '~\Images\LockStatusLOCK.gif' ELSE '~\Images\LockStatusUNLOCK.gif' END AS 'MinibarLockStatusImagePath',

tblMinibars.MinibarCoolerStatus,

CASE WHEN tblMinibars.MinibarCoolerStatus = 'true' THEN 'MinibarCoolerStatusON.gif' ELSE 'MinibarCoolerStatusOFF.gif' END AS 'MinibarCoolerStatusImagePath',

tblMinibars.MinibarModeStatus, tblMinibars.MinibarOfflineStatus,

CASE WHEN tblMinibars.MinibarOfflineStatus = 'true' THEN 'OfflineStatusON.gif' ELSE 'C:\OfflineStatusOFF.gif' END AS 'MinibarOfflineStatusImagePath',

tblMinibars.MinibarCoolingStatus,

CASE WHEN tblMinibars.MinibarCoolingStatus = 'true' THEN 'CoolingStatusAlarmON.gif' ELSE 'CoolingStatusAlarmOFF.gif' END AS 'MinibarCoolingStatusImagePath',

tblMinibars.MinibarDoorOpenStatus,

CASE WHEN tblMinibars.MinibarDoorOpenStatus = 'true' THEN 'DoorOpenStatus.gif' ELSE 'DoorOpenStatusOFF.gif' END AS 'MinibarDoorOpenStatusImagePath',

tblMinibars.MinibarTooManyDoorOpening,

CASE WHEN tblMinibars.MinibarTooManyDoorOpening = 'true' THEN 'TooManyDoorOpeningON.gif' ELSE 'TooManyDoorOpeningOFF.gif' END AS 'MinibarTooManyDoorOpeningImagePath',

tblMinibars.MinibarCourtesyXStatus,

CASE WHEN tblMinibars.MinibarCourtesyXStatus = 'true' THEN 'CourtesyXStatusON.gif' ELSE 'CourtesyXStatusOFF.gif' END AS 'MinibarCourtesyXStatusImagePath',

tblMinibars.MinibarID, tblMinibars.RoomID

FROM tblMinibars INNER JOIN

tblRooms ON tblMinibars.RoomID = tblRooms.RoomID AND tblRooms.IsDeleted = 0 INNER JOIN

tblModelGrids ON tblMinibars.GridID = tblModelGrids.GridID WHERE tblRooms.RoomID=(select DISTINCT RoomID from tblRooms where RoomNumber=@.SingleRoom and IsDele... <-- What is mean by this?

1) how to increase the size of nvarchar(MAX)

2)I am returning strBasicQuery for purpose of it's value.Here issuse is my query character's extending limit of nvarchar(MAX)

Kindly provide solution for me ASAP

The problem is the RETURN statement. Return is the command to exit the procedure and return an exitcode. The exitcode is defined as INT. So, it's natural that your return command generates the error because the system cannot convert @.strBasicQuery to INT.

Instead of using RETURN @.strBasicQuery, you'd do "print @.strBasicQuery".

|||

Quickest way to increase the size of nvarchar(max) is to use varchar(max). I don't seen any UNICODE characters in your query, so use VarChar. that will DOUBLE the number of characters you can use.

varchar(max) is two times the characters of nvarchar(max)

If you must use nvarchar (we have a lot of kanji stuff for example) you'll have to break it up into muliple queries, sorta like this:

Code Snippet

Create Table #Temp(SomeField int)

declare @.cmd nvarchar(max)

set @.cmd = 'insert into #Temp select 1'

exec(@.cmd)

set @.cmd = 'insert into #Temp select 2'

exec (@.cmd)

select * from #temp

|||

>>Quickest way to increase the size of nvarchar(max) is to use varchar(max). I don't seen any UNICODE characters in your query, so use VarChar. that will DOUBLE the number of characters you can use. <<

nvarchar(max) will hold like a billion characters, which is clearly not being taxed. The problem is, as OJ states, that he is trying to return a character, when RETURN in a stored procedure may only return an integer value

|||

problem is not returning values

kindly see error(end section with red color)

What is mean by IsDeleted...<

I am returning @.strBasicQuery for showing you that finally when i run exec(@.strBasicQuery)

it will not execute because my @.strBasicQuery's final value is end like IsDeleted... which is incomplete.

Kindly see error it showing value of @.strBasicQuery

i know that i have to return int not string

kindly provide solution ASAP

|||

problem is not returning values

kindly see error(end section with red color)

What is mean by IsDeleted...<

I am returning @.strBasicQuery for showing you that finally when i run exec(@.strBasicQuery)

it will not execute because my @.strBasicQuery's final value is end like IsDeleted... which is incomplete.

Kindly see error it showing value of @.strBasicQuery

i know that i have to return int not string

kindly provide solution ASAP

|||

problem is not returning values

kindly see error(end section with red color)

What is mean by IsDeleted...<

I am returning @.strBasicQuery for showing you that finally when i run exec(@.strBasicQuery)

it will not execute because my @.strBasicQuery's final value is end like IsDeleted... which is incomplete.

Kindly see error it showing value of @.strBasicQuery

i know that i have to return int not string

kindly provide solution ASAP

|||

The key to this error is: Conversion failed when converting the nvarchar value and i believe it would finish with to datatype int. This is because RETURN expects and integer value as suggested earlier.

However, I wonder if the reason the string is truncated is due to a limitation in the error handling of SQL. I don't think its anything to do with your SQL string being truncated. To test, comment out your EXEC statement and follow the guys advice previously and change:


RETURN @.strBasicQuery

to be:

PRINT @.strBasicQuery

This will give you the SQL String you are trying to execute.

HTH!

|||First, RETURN is expecting an int. You cannot return a string. Change RETURN to PRINT.

Second, the "IsDeleted..." is not your problem. The error message only displays the first 1024 characters of the command.

Third, your real problem is the EXEC command does not access varchar(max), yes I know it says it does, it but doesn't. You need to break your command into multiple varchar(4000) strings and add them together into an EXEC. Like this:

DECLARE @.sql1 varchar(4000), @.sql2 varchar(4000), @.sql3 varchar(4000)

SET @.sql1 = 'SELECT *'
SET @.sql2 = ' FROM TABLEA'
SET @.sql3 = ' WHERE A=A'

EXEC (@.sql1+@.sql2+@.sql3)

|||

Tom Phillips wrote:


Third, your real problem is the EXEC command does not access varchar(max), yes I know it says it does, it but doesn't. You need to break your command into multiple varchar(4000) strings and add them together into an EXEC. Like this:

Tom, that is not correct. Execute can work with varchar(max) just fine. Here is an example for you.

Code Snippet

declare @.var1 varchar(8000), @.var2 varchar(8000), @.sql varchar(max)

set @.var1 = replicate('A',8000)
set @.var2 = replicate('B',8000)
set @.sql = 'select len(''' + cast(@.var1 as varchar(max)) + cast(@.var2 as varchar(max)) + ''')'

exec(@.sql)

|||

Suyog, the problem is the RETURN. Again, you cannot return a string, only INT.

The reason you see the last word "IsDeleted" is because the error message is truncated. It's by no mean cause in this case.

Here is a quick example to stress the point.

Code Snippet

create proc bad
as
declare @.ret varchar(max)
set @.ret = 'I am a string'
return @.ret
go

create proc good
as
declare @.ret int
set @.ret = 999
return @.ret
go

--this will never work!

declare @.return varchar(max)
exec @.return=bad
select @.return [bad]
go

declare @.return int
exec @.return=good
select @.return [good]
go

drop proc bad,good
go

|||oj,

I keep hearing that, and your code works. However, every time I try it in production, it fails. I don't know what the cause is, except if I change it to multiple varchars, instead of varchar(max), it works fine.

|||

Tom Phillips wrote:

oj,

I keep hearing that, and your code works. However, every time I try it in production, it fails. I don't know what the cause is, except if I change it to multiple varchars, instead of varchar(max), it works fine.

You're more than likely hitting "data type precedence" issue.

Let's take a look at previous example, if I forget to convert() to varchar(max), my example would be failing too.

Code Snippet

declare @.var1 varchar(8000), @.var2 varchar(8000), @.sql varchar(max)

set @.var1 = replicate('A',8000)
set @.var2 = replicate('B',8000)
set @.sql = 'select len(''' + @.var1 + @.var2 + ''')'

exec(@.sql)

More info on data type precedence:

http://msdn2.microsoft.com/en-us/library/ms190309.aspx

Thursday, March 8, 2012

Bug in Microsoft SQL Server 2005 JDBC Driver

I am using the new Microsoft SQL Server 2005 JDBC Driver to connect to ms sql 2000. I am testing GMT date conversions in my application and found a bug in the way the driver converts DateTime columns in the ResultSet.getTimeStamp(int i, Calendar cal) method.

The driver is not converting GMT dates to client time correctly in the time range og April 1, 9:00 pm to 10:00 pm EST through the rs.getTimeStamp(int, Calendar) method. The date is coming back an hour off. In UTC time, this time is April 2, 2:00 AM to April 2, 3:00 AM. I guess daylight savings is confusing it. Can someone get back to me with a work around or verification of this bug. Thanks.

Sequence:

1. Set client and server to April 1, 9:05 PM EST. (This is the day before Daylight savings occurs).

2. Run an query on the client from java using the driver.

Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone..getTimeZone("UTC");
Date d;
ResultSet rs = stmt.executeQuery("SELECT getutcdate()");
while(rs.next())
{
d = rs.getTimeStamp(0, cal);
}

System.err.println(d);

Hi Harry,

I think I already replied to you in private email, but I wanted to make sure others scouring the forum are aware as well. This is a bug in the v1.0 SQL Server 2005 JDBC driver. Microsoft will be providing a QFE with a fix. I'll follow up with another post as soon as it becomes available. We are taking some extra time with the fix to make sure it is correct with respect to the subtle nuances of Java's Calendar object, like Daylight Savings Time start and end dates, and historical time zone offset changes.

Thank you for your patience.

--David Olix

JDBC Development

|||

This bug has been now been fixed as a QFE. Please notify CSS that you would like to get the hotfix for KB article 917055.

Again, thank you for your patience,

--David Olix

JDBC Development

Bug in Microsoft SQL Server 2005 JDBC Driver

I am using the new Microsoft SQL Server 2005 JDBC Driver to connect to ms sql 2000. I am testing GMT date conversions in my application and found a bug in the way the driver converts DateTime columns in the ResultSet.getTimeStamp(int i, Calendar cal) method.

The driver is not converting GMT dates to client time correctly in the time range og April 1, 9:00 pm to 10:00 pm EST through the rs.getTimeStamp(int, Calendar) method. The date is coming back an hour off. In UTC time, this time is April 2, 2:00 AM to April 2, 3:00 AM. I guess daylight savings is confusing it. Can someone get back to me with a work around or verification of this bug. Thanks.

Sequence:

1. Set client and server to April 1, 9:05 PM EST. (This is the day before Daylight savings occurs).

2. Run an query on the client from java using the driver.

Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone..getTimeZone("UTC");
Date d;
ResultSet rs = stmt.executeQuery("SELECT getutcdate()");
while(rs.next())
{
d = rs.getTimeStamp(0, cal);
}

System.err.println(d);

Hi Harry,

I think I already replied to you in private email, but I wanted to make sure others scouring the forum are aware as well. This is a bug in the v1.0 SQL Server 2005 JDBC driver. Microsoft will be providing a QFE with a fix. I'll follow up with another post as soon as it becomes available. We are taking some extra time with the fix to make sure it is correct with respect to the subtle nuances of Java's Calendar object, like Daylight Savings Time start and end dates, and historical time zone offset changes.

Thank you for your patience.

--David Olix

JDBC Development

|||

This bug has been now been fixed as a QFE. Please notify CSS that you would like to get the hotfix for KB article 917055.

Again, thank you for your patience,

--David Olix

JDBC Development

bug in focus

so i've got 5 parameters; a couple of booleans
refer to them as
1 2
3 4
5
#2 is the date parameter.. and I keep on getting the date prompt / drop
down...
a) select value for 1, 3, 5
b) enter #2; the value 4/1/06 in the date dropdown
c) mouse focus to #4
d) hit enter when I'm done filling out 4-- since im then DONE filling
in all of my parameters;..
do you know what happens?
i get .dropdown on the datepicker dropdown.
shouldn't they test these things before they start selling it?yeah; i've noticed the same thing.. im surprised MS didn't catch this
-Aaron
On Oct 4, 1:51 pm, "aaron.ke...@.gmail.com" <aaron.ke...@.gmail.com>
wrote:
> so i've got 5 parameters; a couple of booleans
> refer to them as
> 1 2
> 3 4
> 5
> #2 is the date parameter.. and I keep on getting the date prompt / drop
> down...
> a) select value for 1, 3, 5
> b) enter #2; the value 4/1/06 in the date dropdown
> c) mouse focus to #4
> d) hit enter when I'm done filling out 4-- since im then DONE filling
> in all of my parameters;..
> do you know what happens?
> i get .dropdown on the datepicker dropdown.
> shouldn't they test these things before they start selling it?

Sunday, February 19, 2012

Browse date

After I built the cube I clicked browse date in the cube
file and received the message Undefined error. What gives?
How do I access the data. I'm new to this program and was
following the sample program that came with Analysis
Manager.
Thanks for the helpYou should re-post this on the Datawarehouse newsgroup... They should be
able to help you there.
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Gary" <gsylvester@.npgcable.com> wrote in message
news:2b9ea01c46881$22a97fa0$a401280a@.phx.gbl...
> After I built the cube I clicked browse date in the cube
> file and received the message Undefined error. What gives?
> How do I access the data. I'm new to this program and was
> following the sample program that came with Analysis
> Manager.
> Thanks for the help

Browse date

After I built the cube I clicked browse date in the cube
file and received the message Undefined error. What gives?
How do I access the data. I'm new to this program and was
following the sample program that came with Analysis
Manager.
Thanks for the helpYou should re-post this on the Datawarehouse newsgroup... They should be
able to help you there.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Gary" <gsylvester@.npgcable.com> wrote in message
news:2b9ea01c46881$22a97fa0$a401280a@.phx
.gbl...
> After I built the cube I clicked browse date in the cube
> file and received the message Undefined error. What gives?
> How do I access the data. I'm new to this program and was
> following the sample program that came with Analysis
> Manager.
> Thanks for the help

Browse date

After I built the cube I clicked browse date in the cube
file and received the message Undefined error. What gives?
How do I access the data. I'm new to this program and was
following the sample program that came with Analysis
Manager.
Thanks for the help
You should re-post this on the Datawarehouse newsgroup... They should be
able to help you there.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Gary" <gsylvester@.npgcable.com> wrote in message
news:2b9ea01c46881$22a97fa0$a401280a@.phx.gbl...
> After I built the cube I clicked browse date in the cube
> file and received the message Undefined error. What gives?
> How do I access the data. I'm new to this program and was
> following the sample program that came with Analysis
> Manager.
> Thanks for the help

British English Date Problem - ISO-dates not accepted (64-bit)

Problem exists on a 64-bit SQL Server (although the same result occurs on a
32-bit platform), where we have installed MS-SQL with the British English
locale.
We are experiencing problems when passing ISO format dates (yyyy-mm-dd)
within queries. UK date format (25/12/2004) are ok but as soon as an iso
date is used '2004-12-25' an error occurs.
<For example:>
Select * from tbltest where testdate > '2003-04-16 00:00:00'
<Returns error:>
Server: Msg 296, Level 16, State 3, Line 1
The conversion of char data type to smalldatetime data type resulted in an
out-of-range smalldatetime value.
There must be something that we are missing here, as changing the users
locale to the default 'English' (US English) corrects the problem.
Thanks in advance
IanHave a look at these:
http://www.karaszi.com/SQLServer/info_datetime.asp Guide to Datetimes
http://www.sqlservercentral.com/columnists/bsyverson/sqldatetime.asp
Datetimes
http://www.murach.com/books/sqls/article.htm Datetime Searching
I would use the format of 'yyyymmdd' instead.
--
Andrew J. Kelly SQL MVP
"Ian" <Ian@.discussions.microsoft.com> wrote in message
news:77EB65F8-40FE-4BE6-9058-425CFA1F36B8@.microsoft.com...
> Problem exists on a 64-bit SQL Server (although the same result occurs on
> a
> 32-bit platform), where we have installed MS-SQL with the British English
> locale.
> We are experiencing problems when passing ISO format dates (yyyy-mm-dd)
> within queries. UK date format (25/12/2004) are ok but as soon as an iso
> date is used '2004-12-25' an error occurs.
> <For example:>
> Select * from tbltest where testdate > '2003-04-16 00:00:00'
> <Returns error:>
> Server: Msg 296, Level 16, State 3, Line 1
> The conversion of char data type to smalldatetime data type resulted in an
> out-of-range smalldatetime value.
> There must be something that we are missing here, as changing the users
> locale to the default 'English' (US English) corrects the problem.
> Thanks in advance
> Ian|||thanks for the info...
Ian
"Andrew J. Kelly" wrote:
> Have a look at these:
>
> http://www.karaszi.com/SQLServer/info_datetime.asp Guide to Datetimes
> http://www.sqlservercentral.com/columnists/bsyverson/sqldatetime.asp
> Datetimes
> http://www.murach.com/books/sqls/article.htm Datetime Searching
>
> I would use the format of 'yyyymmdd' instead.
> --
> Andrew J. Kelly SQL MVP
>
> "Ian" <Ian@.discussions.microsoft.com> wrote in message
> news:77EB65F8-40FE-4BE6-9058-425CFA1F36B8@.microsoft.com...
> > Problem exists on a 64-bit SQL Server (although the same result occurs on
> > a
> > 32-bit platform), where we have installed MS-SQL with the British English
> > locale.
> >
> > We are experiencing problems when passing ISO format dates (yyyy-mm-dd)
> > within queries. UK date format (25/12/2004) are ok but as soon as an iso
> > date is used '2004-12-25' an error occurs.
> >
> > <For example:>
> >
> > Select * from tbltest where testdate > '2003-04-16 00:00:00'
> >
> > <Returns error:>
> >
> > Server: Msg 296, Level 16, State 3, Line 1
> > The conversion of char data type to smalldatetime data type resulted in an
> > out-of-range smalldatetime value.
> >
> > There must be something that we are missing here, as changing the users
> > locale to the default 'English' (US English) corrects the problem.
> >
> > Thanks in advance
> > Ian
>
>

British English Date Problem - ISO-dates not accepted (64-bit)

Problem exists on a 64-bit SQL Server (although the same result occurs on a
32-bit platform), where we have installed MS-SQL with the British English
locale.
We are experiencing problems when passing ISO format dates (yyyy-mm-dd)
within queries. UK date format (25/12/2004) are ok but as soon as an iso
date is used '2004-12-25' an error occurs.
<For example:>
Select * from tbltest where testdate > '2003-04-16 00:00:00'
<Returns error:>
Server: Msg 296, Level 16, State 3, Line 1
The conversion of char data type to smalldatetime data type resulted in an
out-of-range smalldatetime value.
There must be something that we are missing here, as changing the users
locale to the default 'English' (US English) corrects the problem.
Thanks in advance
Ian
Have a look at these:
http://www.karaszi.com/SQLServer/info_datetime.asp Guide to Datetimes
http://www.sqlservercentral.com/colu...qldatetime.asp
Datetimes
http://www.murach.com/books/sqls/article.htm Datetime Searching
I would use the format of 'yyyymmdd' instead.
Andrew J. Kelly SQL MVP
"Ian" <Ian@.discussions.microsoft.com> wrote in message
news:77EB65F8-40FE-4BE6-9058-425CFA1F36B8@.microsoft.com...
> Problem exists on a 64-bit SQL Server (although the same result occurs on
> a
> 32-bit platform), where we have installed MS-SQL with the British English
> locale.
> We are experiencing problems when passing ISO format dates (yyyy-mm-dd)
> within queries. UK date format (25/12/2004) are ok but as soon as an iso
> date is used '2004-12-25' an error occurs.
> <For example:>
> Select * from tbltest where testdate > '2003-04-16 00:00:00'
> <Returns error:>
> Server: Msg 296, Level 16, State 3, Line 1
> The conversion of char data type to smalldatetime data type resulted in an
> out-of-range smalldatetime value.
> There must be something that we are missing here, as changing the users
> locale to the default 'English' (US English) corrects the problem.
> Thanks in advance
> Ian
|||thanks for the info...
Ian
"Andrew J. Kelly" wrote:

> Have a look at these:
>
> http://www.karaszi.com/SQLServer/info_datetime.asp Guide to Datetimes
> http://www.sqlservercentral.com/colu...qldatetime.asp
> Datetimes
> http://www.murach.com/books/sqls/article.htm Datetime Searching
>
> I would use the format of 'yyyymmdd' instead.
> --
> Andrew J. Kelly SQL MVP
>
> "Ian" <Ian@.discussions.microsoft.com> wrote in message
> news:77EB65F8-40FE-4BE6-9058-425CFA1F36B8@.microsoft.com...
>
>

British date conversation

I am new to VB and have a problem with returning a recordset from a sql string.

I am using visual studio 2005 and SQL server 2005.

I am attempting to return a recordset with the from a table using two date parameters which are held in another table both tables are on the same server. Both tables store their date values in the British “dd/mm/yyy/ HH:MMTongue TiedS AMPM” format when I attempt to create a ADODB dataset using the following code errors occur. I have attempted various different approaches to resolve this but without success. Can you point me in the right direction?

Regards

Joe

@.@.@.@. CODE @.@.@.@.

‘Sub1

Dim Sdate as string, Edate as string

Both parameters are passed to sub2 from sub1

rstmons.movefirst

Sdate = rstMon.Fields("DateAndTimeofFix").Value

rstmon.movelast

Edate = rstMon.Fields("DateAndTimeofFix").Value

‘Sub2

Dim myCONN As String, MonSql As String

myCONN = ("Driver={SQL Server};Provider=SQLOLEDB;Server=midlaptop2;Database=customerlink;Trusted_Connection=Yes;")

MonSql = "SELECT *" & _

" from tblVsol" & _

"WHERE DateAndTimeofFix Between CONVERT(DATETIME,'" & Sdate & _

"') AND CONVERT(DATETIME,'" & Edate & _

"') and vehicleunit = " & iveh & ";"

use convert with style #103

Select Convert(datetime,'31/1/2007 10:10:00', 103) --Correct

Select Convert(datetime,'31/1/2007 10:10:00') -- Error

MonSql = "SELECT *" & _
" from tblVsol" & _
"WHERE DateAndTimeofFix Between CONVERT(DATETIME,'" & Sdate & _
"',103) AND CONVERT(DATETIME,'" & Edate & _
"',103) and vehicleunit = " & iveh & ";"

|||

Hi

Thanks for your prompt reply.

Thats exactly what I needed.

Many Thanks

Joe

|||

Hi JoeBo,

> Both tables store their date values in the British “dd/mm/yyy/ HH:MMS AMPM” format

Unless you are using a character data type (char / nchar / varchar / nvarchar) to store that data, SQL Server does not store datetime data type using any format. The representation for datatime is a two four bytes, 4 bytes for the date and four bytes for the time. SQL Server interprets datetime constant strings based on the settings of SET LANGUAGE / SET DATEFORMAT, but id you want that SQL Server interpret them correctly no matter of those settings, then use styles 112 or 126 (See function CONVERT in BOL). Also, you should parameterize the "select" statement to re-use cached plans, instead concatenating the values and sending the final statement to SQL Server.

Convert Dynamic SQL to Use SQLCommand Parameters Automatically

http://www.knowdotnet.com/articles/dynamicsqlparameters.html

SqlCommand.Parameters Property

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx

Simple Parameterization

http://msdn2.microsoft.com/en-us/library/ms186219.aspx

The ultimate guide to the datetime datatypes

http://www.karaszi.com/SQLServer/info_datetime.asp

AMB

British date conversation

I am new to VB and have a problem with returning a recordset from a sql string.

I am using visual studio 2005 and SQL server 2005.

I am attempting to return a recordset with the from a table using two date parameters which are held in another table both tables are on the same server. Both tables store their date values in the British “dd/mm/yyy/ HH:MMTongue TiedS AMPM” format when I attempt to create a ADODB dataset using the following code errors occur. I have attempted various different approaches to resolve this but without success. Can you point me in the right direction?

Regards

Joe

@.@.@.@. CODE @.@.@.@.

‘Sub1

Dim Sdate as string, Edate as string

Both parameters are passed to sub2 from sub1

rstmons.movefirst

Sdate = rstMon.Fields("DateAndTimeofFix").Value

rstmon.movelast

Edate = rstMon.Fields("DateAndTimeofFix").Value

‘Sub2

Dim myCONN As String, MonSql As String

myCONN = ("Driver={SQL Server};Provider=SQLOLEDB;Server=midlaptop2;Database=customerlink;Trusted_Connection=Yes;")

MonSql = "SELECT *" & _

" from tblVsol" & _

"WHERE DateAndTimeofFix Between CONVERT(DATETIME,'" & Sdate & _

"') AND CONVERT(DATETIME,'" & Edate & _

"') and vehicleunit = " & iveh & ";"

use convert with style #103

Select Convert(datetime,'31/1/2007 10:10:00', 103) --Correct

Select Convert(datetime,'31/1/2007 10:10:00') -- Error

MonSql = "SELECT *" & _
" from tblVsol" & _
"WHERE DateAndTimeofFix Between CONVERT(DATETIME,'" & Sdate & _
"',103) AND CONVERT(DATETIME,'" & Edate & _
"',103) and vehicleunit = " & iveh & ";"

|||

Hi

Thanks for your prompt reply.

Thats exactly what I needed.

Many Thanks

Joe

|||

Hi JoeBo,

> Both tables store their date values in the British “dd/mm/yyy/ HH:MMS AMPM” format

Unless you are using a character data type (char / nchar / varchar / nvarchar) to store that data, SQL Server does not store datetime data type using any format. The representation for datatime is a two four bytes, 4 bytes for the date and four bytes for the time. SQL Server interprets datetime constant strings based on the settings of SET LANGUAGE / SET DATEFORMAT, but id you want that SQL Server interpret them correctly no matter of those settings, then use styles 112 or 126 (See function CONVERT in BOL). Also, you should parameterize the "select" statement to re-use cached plans, instead concatenating the values and sending the final statement to SQL Server.

Convert Dynamic SQL to Use SQLCommand Parameters Automatically

http://www.knowdotnet.com/articles/dynamicsqlparameters.html

SqlCommand.Parameters Property

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx

Simple Parameterization

http://msdn2.microsoft.com/en-us/library/ms186219.aspx

The ultimate guide to the datetime datatypes

http://www.karaszi.com/SQLServer/info_datetime.asp

AMB

British date conversation

I am new to VB and have a problem with returning a recordset from a sql string.

I am using visual studio 2005 and SQL server 2005.

I am attempting to return a recordset with the from a table using two date parameters which are held in another table both tables are on the same server. Both tables store their date values in the British “dd/mm/yyy/ HH:MMTongue TiedS AMPM” format when I attempt to create a ADODB dataset using the following code errors occur. I have attempted various different approaches to resolve this but without success. Can you point me in the right direction?

Regards

Joe

@.@.@.@. CODE @.@.@.@.

‘Sub1

Dim Sdate as string, Edate as string

Both parameters are passed to sub2 from sub1

rstmons.movefirst

Sdate = rstMon.Fields("DateAndTimeofFix").Value

rstmon.movelast

Edate = rstMon.Fields("DateAndTimeofFix").Value

‘Sub2

Dim myCONN As String, MonSql As String

myCONN = ("Driver={SQL Server};Provider=SQLOLEDB;Server=midlaptop2;Database=customerlink;Trusted_Connection=Yes;")

MonSql = "SELECT *" & _

" from tblVsol" & _

"WHERE DateAndTimeofFix Between CONVERT(DATETIME,'" & Sdate & _

"') AND CONVERT(DATETIME,'" & Edate & _

"') and vehicleunit = " & iveh & ";"

use convert with style #103

Select Convert(datetime,'31/1/2007 10:10:00', 103) --Correct

Select Convert(datetime,'31/1/2007 10:10:00') -- Error

MonSql = "SELECT *" & _
" from tblVsol" & _
"WHERE DateAndTimeofFix Between CONVERT(DATETIME,'" & Sdate & _
"',103) AND CONVERT(DATETIME,'" & Edate & _
"',103) and vehicleunit = " & iveh & ";"

|||

Hi

Thanks for your prompt reply.

Thats exactly what I needed.

Many Thanks

Joe

|||

Hi JoeBo,

> Both tables store their date values in the British “dd/mm/yyy/ HH:MMS AMPM” format

Unless you are using a character data type (char / nchar / varchar / nvarchar) to store that data, SQL Server does not store datetime data type using any format. The representation for datatime is a two four bytes, 4 bytes for the date and four bytes for the time. SQL Server interprets datetime constant strings based on the settings of SET LANGUAGE / SET DATEFORMAT, but id you want that SQL Server interpret them correctly no matter of those settings, then use styles 112 or 126 (See function CONVERT in BOL). Also, you should parameterize the "select" statement to re-use cached plans, instead concatenating the values and sending the final statement to SQL Server.

Convert Dynamic SQL to Use SQLCommand Parameters Automatically

http://www.knowdotnet.com/articles/dynamicsqlparameters.html

SqlCommand.Parameters Property

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.parameters.aspx

Simple Parameterization

http://msdn2.microsoft.com/en-us/library/ms186219.aspx

The ultimate guide to the datetime datatypes

http://www.karaszi.com/SQLServer/info_datetime.asp

AMB

Thursday, February 16, 2012

Breakup a group

Thanks in advance and Im new to RS.
I have a simple dataset of date records which can span 1 or more weeks up to
a month, I want to break the list up every time a Wed is encountered as this
is the end of a reporting week and some totals need to be printed at bottom
of the list.
I have been fiddling with a table, but dont seem to be quite able to nut it
out, has anyone else done this or similar at all, comments appreciated.
Thanks, Paul
DataSet...
Tue 2/11 $77 $99 $765
wed 3/11 $50 $450 $999
<Need a break here and total of each column)
Thu 4/11 $23 $888 $987
Fri 5/11 $98 $999 $999
Sat 6/11 $33 $ 99 $999
Sun 7/11 $999 $ 99 $999
Mon 8/11 $999 $ 99 $999
Tue 9/11 $999 $ 99 $999
Wed 10/11 $999 $ 99 $999
<Break here and total>
Thu
etc etc etcPlease ignore this, figured it out in the end. Just needed a grouping value uin
my sql and voila table grouped ok as desired.
"PaulQld" wrote:
> Thanks in advance and Im new to RS.
> I have a simple dataset of date records which can span 1 or more weeks up to
> a month, I want to break the list up every time a Wed is encountered as this
> is the end of a reporting week and some totals need to be printed at bottom
> of the list.
> I have been fiddling with a table, but dont seem to be quite able to nut it
> out, has anyone else done this or similar at all, comments appreciated.
> Thanks, Paul
> DataSet...
> Tue 2/11 $77 $99 $765
> wed 3/11 $50 $450 $999
> <Need a break here and total of each column)
> Thu 4/11 $23 $888 $987
> Fri 5/11 $98 $999 $999
> Sat 6/11 $33 $ 99 $999
> Sun 7/11 $999 $ 99 $999
> Mon 8/11 $999 $ 99 $999
> Tue 9/11 $999 $ 99 $999
> Wed 10/11 $999 $ 99 $999
> <Break here and total>
> Thu
> etc etc etc
>

Breaking up parametersT

One of my parameters is a particular date (in the datetime format 11/05/2002 12:00:00 AM) and I wanted to display only the month and year. How can I do this to just display November 2002 on my report.Try using the DATENAME function. Here's an example using the current date:

declare @.CurrentDate datetime
set @.CurrentDate = GetDate()

select DATENAME(m, @.CurrentDate) + ' ' + DATENAME(yy, @.CurrentDate)

|||Im using visual basic business intelligence. I did figure out the year...

=Year(Parameters!reportdate.Value)

I want the month to be displayed as November, January, July...etc not 11, 1, 7 '

=Month(Parameters!reportdate.Value) gives me 10 which I dont want

and

=MonthName(Parameters!reportdate.Value) gives me an error. I am using SQL 2000.

|||Try the code that I gave above. My output from running the statement

select DATENAME(m, @.CurrentDate) + ' ' + DATENAME(yy, @.CurrentDate)

is:

Column1
-
April 2006
No rows affected.
(1 row(s) returned)

That gives the month name (not number), as you requested...|||Have a look at:
http://msdn2.microsoft.com/en-US/library/ms174395(SQL.90).aspx

It's the documentation for the TSQL DATENAME command.|||

try the following

Switch(Month(Parameters!BeginDate.Value)=01,"January" & Year(Parameters!BeginDate.Value),Month(Parameters!BeginDate.Value)=02,"Feb" & Year( Parameters!BeginDate.Value) )

|||The DATENAME function should also work in SQL Server 2000 - have a look here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_da-db_1dph.asp

Also have a look at this article for some further examples:
http://www.sqljunkies.com/Article/6676BEAE-1967-402D-9578-9A1C7FD826E5.scuk

Tuesday, February 14, 2012

Breaking up parameters

One of my parameters is a particular date (in the datetime format 11/05/2002 12:00:00 AM) and I wanted to display only the month and year. How can I do this to just display November 2002 on my report.Try using the DATENAME function. Here's an example using the current date:

declare @.CurrentDate datetime
set @.CurrentDate = GetDate()

select DATENAME(m, @.CurrentDate) + ' ' + DATENAME(yy, @.CurrentDate)

|||Im using visual basic business intelligence. I did figure out the year...

=Year(Parameters!reportdate.Value)

I want the month to be displayed as November, January, July...etc not 11, 1, 7 '

=Month(Parameters!reportdate.Value) gives me 10 which I dont want

and

=MonthName(Parameters!reportdate.Value) gives me an error. I am using SQL 2000.

|||Try the code that I gave above. My output from running the statement

select DATENAME(m, @.CurrentDate) + ' ' + DATENAME(yy, @.CurrentDate)

is:

Column1
-
April 2006
No rows affected.
(1 row(s) returned)

That gives the month name (not number), as you requested...|||Have a look at:
http://msdn2.microsoft.com/en-US/library/ms174395(SQL.90).aspx

It's the documentation for the TSQL DATENAME command.|||

try the following

Switch(Month(Parameters!BeginDate.Value)=01,"January" & Year(Parameters!BeginDate.Value),Month(Parameters!BeginDate.Value)=02,"Feb" & Year( Parameters!BeginDate.Value) )

|||The DATENAME function should also work in SQL Server 2000 - have a look here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_da-db_1dph.asp

Also have a look at this article for some further examples:
http://www.sqljunkies.com/Article/6676BEAE-1967-402D-9578-9A1C7FD826E5.scuk

Sunday, February 12, 2012

Brain-Dead Newbie - SQL Question

Any help is sincerely appreciated:
I have data in a table that represents the following:
Admin Visit Type Registration Date Discharge Date
D 20050301 20050301
D 20050301 20050301
W 20050301 20050301
E 20050301 20050301
D 20050301 20050302
W 20050301 20050303
W 20050301 20050311
D 20050301 20050301
Patient Type is always and I for the records I want but there are also Patient Types = O which I don't care about..
What I would like to do is accoumlate a counter on the number of Registrations per date as well as Discharges per date.
There can be thousands of registrations per day as well as thousands of discharges per day.
So lets say I want to pass a date parameter to accumulate the total registrations and discharges per day.
I have beat my head against the desk for the last two days because I believe this is a simple query but I just cannot get the results I want - so any help is greatly appreciated.
I have written the following sql but I do not get a sum of the total registrations and discharges and EXPR3 and Expr4 always equal each other which is not the case . For example on 20040301 I have 88 registrations and 17 discharges but I can't ever get the correct totals...
I wrote the following in Query Analyzer - but it does not work and I have went around in circles and have tried so many things I am just frustrated.......
Declare @.Parm_Beg_Date as nvarchar(8)
Set @.Parm_Beg_Date = 20040313

SELECT

Patient_Visit_Result_Master.PVR_Admin_Visit_Type,
Patient_Visit_Result_Master.PVR_Patient_Type,
Patient_Visit_Result_Master.PVR_Registration_Date,
Patient_Visit_Result_Master.PVR_Discharge_Date,
Count(Distinct(Patient_Visit_Result_Master.PVR_Registration_Date)) as Expr3,
Count(Distinct(Patient_Visit_Result_Master.PVR_Discharge_Date)) as Expr4


FROM Patient_Visit_Result_Master INNER JOIN
Patient_Visit_Result_Master Patient_Visit_Result_Master_1 ON
Patient_Visit_Result_Master.PVR_Hospital_ID = Patient_Visit_Result_Master_1.PVR_Hospital_ID AND
@.Parm_Beg_Date = Cast(Patient_Visit_Result_Master_1.PVR_Registration_Date as nvarchar(8))or
@.Parm_Beg_Date = Cast(Patient_Visit_Result_Master_1.PVR_Discharge_Date as nvarchar(8))

WHERE (Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'E')
AND (Patient_Visit_Result_Master.PVR_Patient_Type = 'I')
AND (Cast(Patient_Visit_Result_Master.PVR_Registration_Date as nvarchar(8)) = @.Parm_Beg_Date)

OR (Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'D')
AND (Patient_Visit_Result_Master.PVR_Patient_Type = 'I')
AND (Cast(Patient_Visit_Result_Master.PVR_Registration_Date as nvarchar(8)) = @.Parm_Beg_Date)

Or (Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'W')
AND (Patient_Visit_Result_Master.PVR_Patient_Type = 'I')
and (Cast(Patient_Visit_Result_Master.PVR_Discharge_Date as nvarchar(8)) = @.Parm_Beg_Date)

Or (Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'D')
AND (Patient_Visit_Result_Master.PVR_Patient_Type = 'I')
and (Cast(Patient_Visit_Result_Master.PVR_Discharge_Date as nvarchar(8)) = @.Parm_Beg_Date)

GROUP BY
Patient_Visit_Result_Master.PVR_Admin_Visit_Type,
Patient_Visit_Result_Master.PVR_Patient_Type,
Patient_Visit_Result_Master.PVR_Registration_Date,
Patient_Visit_Result_Master.PVR_Discharge_Date

Order By Patient_Visit_Result_Master.PVR_Admin_Visit_Type
Thanks in advance

One way to do this things is to break down a more complex query into smaller, simplier ones. Build first the join and output the proper data, and store it in a temp table (#tmp). After that worked correctly (the JOIN and WHERE clauses) do the aggregation on the temp table (COUNT).
Of course, you can break it down even more into smaller temp tables checking for each WHERE clause and the do a UNION into a bigger table and then perform the aggregation.
One thing I noticed.. you are using a DISTINCT along with the COUNT... as a general rule, you dont need to use a DISTINCT when counting records...|||Thank you for our reply!
That is the entire issue - I do not want to create an "temp" table and I have been trying to do everything to avoid that solution - and believe I am no SQL guero!
From 1998 to 2005 there are 16.5 million records based on In patients and Out patients - I know I am close (LOL) somewhere - but where!
I think what I will do- after seroius thought is to write a a "stat file" that contains the values I am looking for and have some kind of trigger to populate accordingly.

|||Here are two possible solutions make your tables UNION compatible and use UNIONALL or use CASE statement, try the link below for CASE statement. In SQL Server to use UNION you must have the same datatypes for all table facing the same direction. Run a search fro UNION operator in SQL Server BOL (books online). Hope this helps.
http://www.craigsmullins.com/ssu_0899.htm|||As far as the DISTINCT clause I became desperate! I have NEVER used the Distinct keyword...
I did not want to do a UNION in that I query the file the second time and this is a HUGE file.
Been thinkin about this problem for a couple of days - so I think I will just write some code to accumulate the stats I need and then query from there!
But, thre still has to be a way to accomplish this in some sort of way - without writing some sort of stat file.
Thank you and best regards,

|||Why do you want to avoid using temp tables? they are a great tool when dealing with complex queries! and it will make your future maintenance work easier too.
by temp tables i do not mean creating a REAL table (that is not necessary) but in-memory tables that you drop after your query is complete, example:
select * into #temp from Customers
will create an in-memory table that will hold all the customers table data.
after you query is complete you execute:
drop table #temp
and thats it.|||Ok - I will try this - thank you.
I did not realize there were temporary tables in that a lot of stuff I have read I have seen that people create "in line" tables where they define all of the fields etceteras - that's why this forum has been great for me ---
Is there any problems when multiple people access the query with using #temp as the temporary table name - or do I use date and time as the table name ?
Can you create multiple temp tables and then do a join on them as well?
Really - thanks - I will try and post back.
Best Regards,

|||

As in the query I explained above, you can create an in-memory temp table on the fly and do not need to specify any of its fields, it will just be a replica of the table you are copying. Nobody can access your temp table outside of the current connection that you established, and yes, you can do JOINS, UNIONS, etc...
That is why, going back to your first point, I would divide the query in multiple steps. Each step will generate a temp table and after checking each step has been fulfilled properly I would join them and perform the rest of operations. Remember you don't need the DISTINCT in the COUNT

|||

"JAVIGUILLEN"

I am really glad I found this forum!!!
Sincere THANKS! You were correct - this is very simple - wished I knew about the #temp tables before - I just don't know after all of the "stinking" searching I have done why I missed this capability?

Anyway, this is what I wrote and works pretty well - after I got messing with the Into - I only inserted the fields I needed in the temp tables instead of the other 60 plus fields that are in the table.
I also threw this into a stored procedure..... This SP will do this for Day, Week, Month, Quarter and Year. Should I consider the ALTER procedure or With RECOMPILE option - I have looked at these two alternatives but don't really understand YET...
This SQL stuff is pretty cool and I am excited...I am sure once you get pretty good you can do all kinds of magical stuff.

Declare @.Parm_Beg_Date as nvarchar(8)
Declare @.Parm_Hospital as nvarchar(10)
/***** Accumulate Total Registrations for the Period Passeds as @.Parm_Beg_Date *****/
SELECT
Patient_Visit_Result_Master.PVR_Hospital_ID,
Cast(Patient_Visit_Result_Master.PVR_Registration_Date as nvarchar(8)) PVR_Registration_Date,
Patient_Visit_Result_Master.PVR_Ward_ID,
Count(1) AS Registrations
INTO #Temp
FROM Patient_Visit_Result_Master
INNER JOIN
Hospital_Ward_Master
ON Patient_Visit_Result_Master.PVR_Hospital_ID = Hospital_Ward_Master.HWM_Hospital_ID
AND Patient_Visit_Result_Master.PVR_Ward_ID = Hospital_Ward_Master.HWM_Ward_ID
WHERE Patient_Visit_Result_Master.PVR_Hospital_ID = @.Parm_Hospital
AND Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'W'
AND Patient_Visit_Result_Master.PVR_Patient_Type = 'I'
AND @.Parm_Beg_Date = Cast(Patient_Visit_Result_Master.PVR_Registration_Date AS nvarchar(8))
OR Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'D'
AND Patient_Visit_Result_Master.PVR_Patient_Type = 'I'
AND @.Parm_Beg_Date = Cast(Patient_Visit_Result_Master.PVR_Registration_Date AS nvarchar(8))
GROUP BY
Patient_Visit_Result_Master.PVR_Hospital_ID,
Patient_Visit_Result_Master.PVR_Registration_Date,
Patient_Visit_Result_Master.PVR_Ward_ID

/***** Accumulte Total Discharges for the Period Passed as @.Parm_Beg_Date
SELECT
Patient_Visit_Result_Master.PVR_Hospital_ID,
Cast(Patient_Visit_Result_Master.PVR_Discharge_Date as nvarchar(8)) as PVR_Discharge_Date,
Patient_Visit_Result_Master.PVR_Ward_ID,
Count(1) AS Discharges
INTO #Temp1
FROM Patient_Visit_Result_Master

WHERE Patient_Visit_Result_Master.PVR_Hospital_ID = @.Parm_Hospital
AND Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'W'
AND Patient_Visit_Result_Master.PVR_Patient_Type = 'I'
AND @.Parm_Beg_Date = Cast(Patient_Visit_Result_Master.PVR_Discharge_Date AS nvarchar(8))
OR Patient_Visit_Result_Master.PVR_Admin_Visit_Type = 'D'
AND Patient_Visit_Result_Master.PVR_Patient_Type = 'I'
AND @.Parm_Beg_Date = Cast(Patient_Visit_Result_Master.PVR_Discharge_Date AS nvarchar(8))
GROUP BY
Patient_Visit_Result_Master.PVR_Hospital_ID,
Patient_Visit_Result_Master.PVR_Ward_ID,
Patient_Visit_Result_Master.PVR_Discharge_Date
/***** Join Total Registrations and Total Discharges for the Period Passed and Cast the fields the Report Data Set is Expecting ****/
SELECT
#Temp.PVR_Hospital_ID as PVR_Hospital_ID,
Cast(#Temp.PVR_Registration_Date as nvarchar (8))PVR_Registration_Date,
Cast(#Temp1.PVR_Discharge_Date as nvarchar(8)) PVR_Discharge_Date,
#Temp.PVR_Ward_ID as PVR_Ward_ID,
#Temp.Registrations + #Temp1.Discharges AS Expr1,
#Temp.Registrations + #Temp1.Discharges AS Expr2,
#Temp.Registrations as Expr3,
#Temp1.Discharges as Expr4,
Hospital_Ward_Master.HWM_Ward_Name,
CAST(@.Parm_Beg_Date AS nvarchar(8)) AS wrkdate,
wrkdate as LabelDescr1,
' ' as LabelDescr2,
'By Day' as LabelDescr
FROM #Temp
INNER JOIN
#Temp1
ON #Temp.PVR_Hospital_ID = #Temp1.PVR_Hospital_ID
INNER JOIN
Hospital_Ward_Master ON
#Temp.PVR_Ward_ID = Hospital_Ward_Master.HWM_Ward_ID

Group By
#Temp.PVR_Hospital_ID,
#Temp.PVR_Ward_ID,
Hospital_Ward_Master.HWM_Ward_Name,
PVR_Registration_Date,
PVR_Discharge_Date,
#Temp.Registrations,
#Temp1.Discharges

Drop Table #Temp
Drop Table #Temp1

|||I am glad I was able to help :)|||the ALTER functionality is used when you want to modify a stored procedure that already exists in the database.
RECOMPILE forces SQL Server to NOT use any cached version of the stored procedure that might have been created. Its used if you make a change in the code but SQL Server doesnt recognize it because it is using a cached version instead...