Unix Technical Forum

Internal SQL Server error when using variable

This is a discussion on Internal SQL Server error when using variable within the SQL Server forums, part of the Microsoft SQL Server category; --> In the code below I get an Internal SQL Server error in Query Analyzer. Ultimately I want to get ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 05:22 AM
Carl Ganz
 
Posts: n/a
Default Internal SQL Server error when using variable

In the code below I get an Internal SQL Server error in Query
Analyzer. Ultimately I want to get thos code working in a function.

DECLARE @WeekNumber tinyint
DECLARE @Comp decimal(18,2)
DECLARE @PeriodFromDate datetime
DECLARE @PeriodToDate datetime

SET @WeekNumber = 27

SET @PeriodFromDate = (SELECT MIN(StartDate) AS StartDate FROM
Calendar WHERE WeekNumber = @WeekNumber)

SET @PeriodToDate = (SELECT MAX(EndDate) AS StartDate FROM Calendar
WHERE WeekNumber = @WeekNumber)

SET @Comp = (SELECT SUM(ActualGrossComp)
FROM dbo.fnc_ProgramLineUp_1_2()
WHERE Delay > 0
AND ClearanceCode <> 3
AND TeleCastDate BETWEEN @PeriodFromDate AND PeriodToDate)


But this code runs fine:


DECLARE @WeekNumber tinyint
DECLARE @Comp decimal(18,2)
DECLARE @PeriodFromDate datetime
DECLARE @PeriodToDate datetime

SET @WeekNumber = 27

SET @PeriodFromDate = (SELECT MIN(StartDate) AS StartDate FROM
Calendar WHERE WeekNumber = @WeekNumber)

SET @PeriodToDate = (SELECT MAX(EndDate) AS StartDate FROM Calendar
WHERE WeekNumber = @WeekNumber)

SELECT SUM(ActualGrossComp)
FROM dbo.fnc_ProgramLineUp_1_2()
WHERE Delay > 0
AND ClearanceCode <> 3
AND TeleCastDate BETWEEN @PeriodFromDate AND PeriodToDate


The only difference is that here I'm not setting @Comp to the return
value of the SELECT. This code also runs fine when I sum other
columns. Any ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 05:23 AM
Muhd
 
Posts: n/a
Default Re: Internal SQL Server error when using variable

I didn't actually try this but it looks like you want this instead:

SELECT @Comp = SUM(ActualGrossComp)
FROM dbo.fnc_ProgramLineUp_1_2()
WHERE Delay > 0
AND ClearanceCode <> 3
AND TeleCastDate BETWEEN @PeriodFromDate AND PeriodToDate

Instead of trying to select into a set statement you simply use the select
statement to set your own variable.

Best,
Muhd


"Carl Ganz" <seton.software@verizon.net> wrote in message
news:a1d35f16.0409271012.32733e01@posting.google.c om...
> In the code below I get an Internal SQL Server error in Query
> Analyzer. Ultimately I want to get thos code working in a function.
>
> DECLARE @WeekNumber tinyint
> DECLARE @Comp decimal(18,2)
> DECLARE @PeriodFromDate datetime
> DECLARE @PeriodToDate datetime
>
> SET @WeekNumber = 27
>
> SET @PeriodFromDate = (SELECT MIN(StartDate) AS StartDate FROM
> Calendar WHERE WeekNumber = @WeekNumber)
>
> SET @PeriodToDate = (SELECT MAX(EndDate) AS StartDate FROM Calendar
> WHERE WeekNumber = @WeekNumber)
>
> SET @Comp = (SELECT SUM(ActualGrossComp)
> FROM dbo.fnc_ProgramLineUp_1_2()
> WHERE Delay > 0
> AND ClearanceCode <> 3
> AND TeleCastDate BETWEEN @PeriodFromDate AND PeriodToDate)
>
>
> But this code runs fine:
>
>
> DECLARE @WeekNumber tinyint
> DECLARE @Comp decimal(18,2)
> DECLARE @PeriodFromDate datetime
> DECLARE @PeriodToDate datetime
>
> SET @WeekNumber = 27
>
> SET @PeriodFromDate = (SELECT MIN(StartDate) AS StartDate FROM
> Calendar WHERE WeekNumber = @WeekNumber)
>
> SET @PeriodToDate = (SELECT MAX(EndDate) AS StartDate FROM Calendar
> WHERE WeekNumber = @WeekNumber)
>
> SELECT SUM(ActualGrossComp)
> FROM dbo.fnc_ProgramLineUp_1_2()
> WHERE Delay > 0
> AND ClearanceCode <> 3
> AND TeleCastDate BETWEEN @PeriodFromDate AND PeriodToDate
>
>
> The only difference is that here I'm not setting @Comp to the return
> value of the SELECT. This code also runs fine when I sum other
> columns. Any ideas?



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 05:29 AM
Carl Ganz
 
Posts: n/a
Default Re: Internal SQL Server error when using variable

Thanks for the feedback. Your solution did work. Microsoft tech
support believes my initial problem to be a bug and suggested
INSERTING into an in-memory table.

Thanks

Carl Ganz

"Muhd" <eat@joes.com> wrote in message news:<pQ_5d.546211$gE.52683@pd7tw3no>...
> I didn't actually try this but it looks like you want this instead:
>
> SELECT @Comp = SUM(ActualGrossComp)
> FROM dbo.fnc_ProgramLineUp_1_2()
> WHERE Delay > 0
> AND ClearanceCode <> 3
> AND TeleCastDate BETWEEN @PeriodFromDate AND PeriodToDate
>
> Instead of trying to select into a set statement you simply use the select
> statement to set your own variable.
>
> Best,
> Muhd
>
>
> "Carl Ganz" <seton.software@verizon.net> wrote in message
> news:a1d35f16.0409271012.32733e01@posting.google.c om...
> > In the code below I get an Internal SQL Server error in Query
> > Analyzer. Ultimately I want to get thos code working in a function.
> >
> > DECLARE @WeekNumber tinyint
> > DECLARE @Comp decimal(18,2)
> > DECLARE @PeriodFromDate datetime
> > DECLARE @PeriodToDate datetime
> >
> > SET @WeekNumber = 27
> >
> > SET @PeriodFromDate = (SELECT MIN(StartDate) AS StartDate FROM
> > Calendar WHERE WeekNumber = @WeekNumber)
> >
> > SET @PeriodToDate = (SELECT MAX(EndDate) AS StartDate FROM Calendar
> > WHERE WeekNumber = @WeekNumber)
> >
> > SET @Comp = (SELECT SUM(ActualGrossComp)
> > FROM dbo.fnc_ProgramLineUp_1_2()
> > WHERE Delay > 0
> > AND ClearanceCode <> 3
> > AND TeleCastDate BETWEEN @PeriodFromDate AND PeriodToDate)
> >
> >
> > But this code runs fine:
> >
> >
> > DECLARE @WeekNumber tinyint
> > DECLARE @Comp decimal(18,2)
> > DECLARE @PeriodFromDate datetime
> > DECLARE @PeriodToDate datetime
> >
> > SET @WeekNumber = 27
> >
> > SET @PeriodFromDate = (SELECT MIN(StartDate) AS StartDate FROM
> > Calendar WHERE WeekNumber = @WeekNumber)
> >
> > SET @PeriodToDate = (SELECT MAX(EndDate) AS StartDate FROM Calendar
> > WHERE WeekNumber = @WeekNumber)
> >
> > SELECT SUM(ActualGrossComp)
> > FROM dbo.fnc_ProgramLineUp_1_2()
> > WHERE Delay > 0
> > AND ClearanceCode <> 3
> > AND TeleCastDate BETWEEN @PeriodFromDate AND PeriodToDate
> >
> >
> > The only difference is that here I'm not setting @Comp to the return
> > value of the SELECT. This code also runs fine when I sum other
> > columns. Any ideas?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:20 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com