• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

Unexpected error when CTE used in query (1 Viewer)

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 02:38
Joined
Jan 20, 2009
Messages
12,078
I have a CTE I want to use in a big query. The CTE works perfectly.

The big query works perfectly until I join in the simple subquery that uses the CTE.

Once combined, the big query returns two records then throws an error:
Code:
'Cannot convert a char value to money. The char value has incorrect syntax.'

The line referred to in the error is the first line of the CTE declaration: WITH ctename AS ( etc

There are no conversions from char to money in the CTE or the big query and no joins between char and money columns.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 02:38
Joined
Jan 20, 2009
Messages
12,078
Found it.:oops:

I had used COALESCE on a money column with a string as the Null replacement in the subquery that used the CTE.
 

Minty

AWF VIP
Local time
Today, 16:38
Joined
Jul 26, 2013
Messages
7,349
I find CTE's quite confusing sometimes.
I think I still have only got about 60% of their "mojo" into my brain, and the other 40% is the clever bit, which I still haven't really grasped.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 02:38
Joined
Jan 20, 2009
Messages
12,078
I find CTE's quite confusing sometimes.
I think I still have only got about 60% of their "mojo" into my brain, and the other 40% is the clever bit, which I still haven't really grasped.
CTEs are like sub queries that only run once at the beginning of the main query with their results able to be subsequently used throughout. More or less like starting a sequence of queries in Access that begin with a make table query but without actually being written to the disk.

They are particularly useful when requiring consistent output that needs to be used multiple times from non-deterministic functions such as ROW_NUMBER().
 

Minty

AWF VIP
Local time
Today, 16:38
Joined
Jul 26, 2013
Messages
7,349
@Galaxiom - That's one of the best descriptions I've come across, and actually clears up a good deal of the wooliness I had. Thank you.

I've used them quite a bit in recursive lookups in SQL server, and whilst I can always make them work, sometimes I'm not entirely certain of how I've made it work, that will help me a lot.
 

Users who are viewing this thread

Top Bottom