473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

SQL Query Translate to Pass Through Query Problem

Hi
I use SQLServer2000 and MS Access2000
I have the below SQL query which will not work as a Access PassThrough
Query, I have tried replacing the @COB with a date string but the query
hangs forever.
Can anyone direct me the right way?
Thanks
Kay

DECLARE @cob smalldatetime
SELECT @cob = '20060616'

SELECT field1,
field2,
field3,
@cob as report_date
FROM table1
WHERE business_date = @cob
AND field1 in (
SELECT field1
FROM table1
WHERE business_date = @cob
AND field9 = 'N'
AND field10 <> -1
GROUP BY field1)
GROUP BY field1,field2,field3

Jun 19 '06 #1
5 5203
You need to use the convert function to handle string to dates conversion
properly.

Assuming your date is in the format yyyymmdd then you would do something
like:-

DECLARE @cob smalldatetime

SELECT @cob = convert(smalldatetime, '20060616', 112)
Look in BOL at the "CAST and CONVERT" topic for valid values for the third
argument of convert and how tey relate to the date format you're converting
from.
--

Terry Kreft
"KayC" <ka******@yahoo.co.uk> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Hi
I use SQLServer2000 and MS Access2000
I have the below SQL query which will not work as a Access PassThrough
Query, I have tried replacing the @COB with a date string but the query
hangs forever.
Can anyone direct me the right way?
Thanks
Kay

DECLARE @cob smalldatetime
SELECT @cob = '20060616'

SELECT field1,
field2,
field3,
@cob as report_date
FROM table1
WHERE business_date = @cob
AND field1 in (
SELECT field1
FROM table1
WHERE business_date = @cob
AND field9 = 'N'
AND field10 <> -1
GROUP BY field1)
GROUP BY field1,field2,field3

Jun 19 '06 #2
Hi Terry
Thanks for the suggestion
I have tried this and Access still complains with the same error
message below:
Pass-Through query with ReturnsRecords property set to True did not
return any records

Regards
Kay

Terry Kreft wrote:
You need to use the convert function to handle string to dates conversion
properly.

Assuming your date is in the format yyyymmdd then you would do something
like:-

DECLARE @cob smalldatetime

SELECT @cob = convert(smalldatetime, '20060616', 112)
Look in BOL at the "CAST and CONVERT" topic for valid values for the third
argument of convert and how tey relate to the date format you're converting
from.
--

Terry Kreft
"KayC" <ka******@yahoo.co.uk> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Hi
I use SQLServer2000 and MS Access2000
I have the below SQL query which will not work as a Access PassThrough
Query, I have tried replacing the @COB with a date string but the query
hangs forever.
Can anyone direct me the right way?
Thanks
Kay

DECLARE @cob smalldatetime
SELECT @cob = '20060616'

SELECT field1,
field2,
field3,
@cob as report_date
FROM table1
WHERE business_date = @cob
AND field1 in (
SELECT field1
FROM table1
WHERE business_date = @cob
AND field9 = 'N'
AND field10 <> -1
GROUP BY field1)
GROUP BY field1,field2,field3


Jun 20 '06 #3
Well, this isn't the same error is it, because you weren't getting an error
before acording to your original post.

Anyway, where you have

SELECT @cob = convert(smalldatetime, '20060616', 112)
Change this to

SET NOCOUNT ON
SELECT @cob = convert(smalldatetime, '20060616', 112)
And then at the end put
SET NOCOUNT OFF

--

Terry Kreft
"KayC" <ka******@yahoo.co.uk> wrote in message
news:11*********************@y41g2000cwy.googlegro ups.com...
Hi Terry
Thanks for the suggestion
I have tried this and Access still complains with the same error
message below:
Pass-Through query with ReturnsRecords property set to True did not
return any records

Regards
Kay

Terry Kreft wrote:
You need to use the convert function to handle string to dates conversion properly.

Assuming your date is in the format yyyymmdd then you would do something
like:-

DECLARE @cob smalldatetime

SELECT @cob = convert(smalldatetime, '20060616', 112)
Look in BOL at the "CAST and CONVERT" topic for valid values for the third argument of convert and how tey relate to the date format you're converting from.
--

Terry Kreft
"KayC" <ka******@yahoo.co.uk> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
Hi
I use SQLServer2000 and MS Access2000
I have the below SQL query which will not work as a Access PassThrough
Query, I have tried replacing the @COB with a date string but the query hangs forever.
Can anyone direct me the right way?
Thanks
Kay

DECLARE @cob smalldatetime
SELECT @cob = '20060616'

SELECT field1,
field2,
field3,
@cob as report_date
FROM table1
WHERE business_date = @cob
AND field1 in (
SELECT field1
FROM table1
WHERE business_date = @cob
AND field9 = 'N'
AND field10 <> -1
GROUP BY field1)
GROUP BY field1,field2,field3

Jun 20 '06 #4
By the way, I don' really understand why you are using such a convoluted
piece of SQL.

Where you have
SELECT
field1,
field2,
field3,
@cob report_date
FROM
table1
WHERE
business_date = @cob
AND
field1 in (
SELECT
field1
FROM
table1
WHERE
business_date = @cob
AND
field9 = 'N'
AND
field10 <> -1
GROUP BY field1
)
GROUP BY field1,field2,field3

I would have
SELECT DISTINCT
field1,
field2,
field3,
@cob report_date
FROM
table1
WHERE
business_date = @cob
AND
field9 = 'N'
AND
field10 <> -1

which would be faster to execute.

--

Terry Kreft
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:zh********************@karoo.co.uk...
Well, this isn't the same error is it, because you weren't getting an error before acording to your original post.

Anyway, where you have

SELECT @cob = convert(smalldatetime, '20060616', 112)
Change this to

SET NOCOUNT ON
SELECT @cob = convert(smalldatetime, '20060616', 112)
And then at the end put
SET NOCOUNT OFF

--

Terry Kreft
"KayC" <ka******@yahoo.co.uk> wrote in message
news:11*********************@y41g2000cwy.googlegro ups.com...
Hi Terry
Thanks for the suggestion
I have tried this and Access still complains with the same error
message below:
Pass-Through query with ReturnsRecords property set to True did not
return any records

Regards
Kay

Terry Kreft wrote:
You need to use the convert function to handle string to dates conversion properly.

Assuming your date is in the format yyyymmdd then you would do something like:-

DECLARE @cob smalldatetime

SELECT @cob = convert(smalldatetime, '20060616', 112)
Look in BOL at the "CAST and CONVERT" topic for valid values for the third argument of convert and how tey relate to the date format you're converting from.
--

Terry Kreft
"KayC" <ka******@yahoo.co.uk> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
> Hi
> I use SQLServer2000 and MS Access2000
> I have the below SQL query which will not work as a Access PassThrough > Query, I have tried replacing the @COB with a date string but the query > hangs forever.
> Can anyone direct me the right way?
> Thanks
> Kay
>
> DECLARE @cob smalldatetime
> SELECT @cob = '20060616'
>
> SELECT field1,
> field2,
> field3,
> @cob as report_date
> FROM table1
> WHERE business_date = @cob
> AND field1 in (
> SELECT field1
> FROM table1
> WHERE business_date = @cob
> AND field9 = 'N'
> AND field10 <> -1
> GROUP BY field1)
> GROUP BY field1,field2,field3
>


Jun 20 '06 #5
Terry,
It looks like the pass through query was taking so long due to the
'convoluted' sql, works now with the nested sql taken out
Thanks again
Kay
Terry Kreft wrote:
By the way, I don' really understand why you are using such a convoluted
piece of SQL.

Where you have
SELECT
field1,
field2,
field3,
@cob report_date
FROM
table1
WHERE
business_date = @cob
AND
field1 in (
SELECT
field1
FROM
table1
WHERE
business_date = @cob
AND
field9 = 'N'
AND
field10 <> -1
GROUP BY field1
)
GROUP BY field1,field2,field3

I would have
SELECT DISTINCT
field1,
field2,
field3,
@cob report_date
FROM
table1
WHERE
business_date = @cob
AND
field9 = 'N'
AND
field10 <> -1

which would be faster to execute.

--

Terry Kreft
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:zh********************@karoo.co.uk...
Well, this isn't the same error is it, because you weren't getting an

error
before acording to your original post.

Anyway, where you have

SELECT @cob = convert(smalldatetime, '20060616', 112)
Change this to

SET NOCOUNT ON
SELECT @cob = convert(smalldatetime, '20060616', 112)
And then at the end put
SET NOCOUNT OFF

--

Terry Kreft
"KayC" <ka******@yahoo.co.uk> wrote in message
news:11*********************@y41g2000cwy.googlegro ups.com...
Hi Terry
Thanks for the suggestion
I have tried this and Access still complains with the same error
message below:
Pass-Through query with ReturnsRecords property set to True did not
return any records

Regards
Kay

Terry Kreft wrote:

> You need to use the convert function to handle string to dates

conversion
> properly.
>
> Assuming your date is in the format yyyymmdd then you would do something > like:-
>
> DECLARE @cob smalldatetime
>
> SELECT @cob = convert(smalldatetime, '20060616', 112)
>
>
> Look in BOL at the "CAST and CONVERT" topic for valid values for the

third
> argument of convert and how tey relate to the date format you're

converting
> from.
>
>
> --
>
> Terry Kreft
>
>
> "KayC" <ka******@yahoo.co.uk> wrote in message
> news:11**********************@g10g2000cwb.googlegr oups.com...
> > Hi
> > I use SQLServer2000 and MS Access2000
> > I have the below SQL query which will not work as a Access PassThrough > > Query, I have tried replacing the @COB with a date string but the

query
> > hangs forever.
> > Can anyone direct me the right way?
> > Thanks
> > Kay
> >
> > DECLARE @cob smalldatetime
> > SELECT @cob = '20060616'
> >
> > SELECT field1,
> > field2,
> > field3,
> > @cob as report_date
> > FROM table1
> > WHERE business_date = @cob
> > AND field1 in (
> > SELECT field1
> > FROM table1
> > WHERE business_date = @cob
> > AND field9 = 'N'
> > AND field10 <> -1
> > GROUP BY field1)
> > GROUP BY field1,field2,field3
> >



Jun 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex | last post by:
Subject: Looking for an XML (database-based) Query Reporting Tool/advice First off, let me apologize if this thread is somewhat off topic... PLEASE REPLY TO: xml@solex-bi.com I am looking...
5
by: Bob Stearns | last post by:
When I run the following query with the two sections commented out, the response time is between 1 an 2 seconds; with the first indicated section enabled, the response goes up to 15 seconds even...
1
by: ED | last post by:
I currently have an ODBC query that hits an Oracle database. I want to bring back records for a given month based on a job completion date in the Oracle database. I would like to have the user...
9
by: DFS | last post by:
The following data set is building inspection visits. It consists of multiple visits (2+) made to the same building on the same day. I want to get a list of visits made to the same building on...
10
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a...
5
by: PHPBABY3 | last post by:
Hi, 1. I have two SQL tables. I will call them employees and departments: EMP: LAST_NAME, FIRST_NAME, DEPTNM DEPT: NUM, NAME Input: text string FIND Output: the LAST_NAME, FIRST_NAME...
5
by: Frank Jovi | last post by:
I am working on a website with ASP.NET 2.0 I started with a SQL database .mdf. After further discussions with my client, we decided to switch to an Access database. I created a Select query...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
0
by: =?UTF-8?B?TmlscyBPbGl2ZXIgS3LDtmdlcg==?= | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I don't think the global interpreter lock is what you need ... read here for reference: http://docs.python.org/api/threads.html
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.