UPDATE QUERY PLEASE HELP!

G

Guest

I have been working on this for two days and can not find a solution. It
works perfectly as an select and Append query but not as an update query.

In a nutshell:

I have a query (select) with 5 tables. One of the tables is a target table
and the other 4 are source tables. In 3 of the fields I have this expression..
Attachments: IIf(dbo_tblProductversion.Attachments=True,"Y","N")

I have this because these fields are Y/N datatypes.

I am tryig to update these three fields (different names of course)with the
same expressions. I want them and other fileds (approx 15) to update into my
target table.
I am now ready for my update table and selct it. When I add this expression
it will not allow me to select the table where this expression came from nor
will it allow me to add in my update to info. I get the following error along
with trying to run the update query..

"dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]is
not a valid name. Make sure that it does not include invalid characters or
punctuation and tha it is not too long."

Can someone help me with this? It should be a simple update. The select
works fine and I am just trying to update one table with this expression. I
have heard everythingfrom cant do it to move all the info to the #1 position.
HELP!
 
T

Tom Ellison

Dear Troy:

I think you're so, so close.

When you test the Attachments column, you use the keyword "True" in the test
(without the quotes!). If you are setting another yes/no column's value,
use True and False, not "Y" and "N".

This thing:

dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]

Your use of square brackets is not balanced, and probably not needed.
Parens are also not balanced. Each left bracket or paren must be balanced
by a right one. How about:

dbo_tblproductversion.IIf(dbo_tblproductversion.eandoflag = true, true,
false)

I leave testing the spelling of your table and column names to you.

Tom Ellison
 
G

Guest

Thank you for your help. I get a syntax error with this. It seems my
expression worked in the select query and the append query that I did. It
also worked up to the point until I made it an pdate query. That is where the
problem is (I think?) in the update portion of this mess. Any additional
ideas would be appreciated. I have received approx 10 different responses and
getting closer everytime. I really appreciate everyones help in helping me
get through this. My time limit is almost up and I really need to get on the
road with this thing. Thanks again

Tom Ellison said:
Dear Troy:

I think you're so, so close.

When you test the Attachments column, you use the keyword "True" in the test
(without the quotes!). If you are setting another yes/no column's value,
use True and False, not "Y" and "N".

This thing:

dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]

Your use of square brackets is not balanced, and probably not needed.
Parens are also not balanced. Each left bracket or paren must be balanced
by a right one. How about:

dbo_tblproductversion.IIf(dbo_tblproductversion.eandoflag = true, true,
false)

I leave testing the spelling of your table and column names to you.

Tom Ellison


troy said:
I have been working on this for two days and can not find a solution. It
works perfectly as an select and Append query but not as an update query.

In a nutshell:

I have a query (select) with 5 tables. One of the tables is a target table
and the other 4 are source tables. In 3 of the fields I have this
expression..
Attachments: IIf(dbo_tblProductversion.Attachments=True,"Y","N")

I have this because these fields are Y/N datatypes.

I am tryig to update these three fields (different names of course)with
the
same expressions. I want them and other fileds (approx 15) to update into
my
target table.
I am now ready for my update table and selct it. When I add this
expression
it will not allow me to select the table where this expression came from
nor
will it allow me to add in my update to info. I get the following error
along
with trying to run the update query..

"dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]is
not a valid name. Make sure that it does not include invalid characters or
punctuation and tha it is not too long."

Can someone help me with this? It should be a simple update. The select
works fine and I am just trying to update one table with this expression.
I
have heard everythingfrom cant do it to move all the info to the #1
position.
HELP!
 
T

Tom Ellison

Dear Troy:

Please post the SQL of your entire query. I'll look at it and try to find
an error.

Alternatively, remove portions of the query till you find where the error
is. Once you know where it is, fixing it is relatively easy.

Tom Ellison


troy said:
Thank you for your help. I get a syntax error with this. It seems my
expression worked in the select query and the append query that I did. It
also worked up to the point until I made it an pdate query. That is where
the
problem is (I think?) in the update portion of this mess. Any additional
ideas would be appreciated. I have received approx 10 different responses
and
getting closer everytime. I really appreciate everyones help in helping me
get through this. My time limit is almost up and I really need to get on
the
road with this thing. Thanks again

Tom Ellison said:
Dear Troy:

I think you're so, so close.

When you test the Attachments column, you use the keyword "True" in the
test
(without the quotes!). If you are setting another yes/no column's value,
use True and False, not "Y" and "N".

This thing:

dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]

Your use of square brackets is not balanced, and probably not needed.
Parens are also not balanced. Each left bracket or paren must be
balanced
by a right one. How about:

dbo_tblproductversion.IIf(dbo_tblproductversion.eandoflag = true, true,
false)

I leave testing the spelling of your table and column names to you.

Tom Ellison


troy said:
I have been working on this for two days and can not find a solution. It
works perfectly as an select and Append query but not as an update
query.

In a nutshell:

I have a query (select) with 5 tables. One of the tables is a target
table
and the other 4 are source tables. In 3 of the fields I have this
expression..
Attachments: IIf(dbo_tblProductversion.Attachments=True,"Y","N")

I have this because these fields are Y/N datatypes.

I am tryig to update these three fields (different names of course)with
the
same expressions. I want them and other fileds (approx 15) to update
into
my
target table.
I am now ready for my update table and selct it. When I add this
expression
it will not allow me to select the table where this expression came
from
nor
will it allow me to add in my update to info. I get the following error
along
with trying to run the update query..

"dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]is
not a valid name. Make sure that it does not include invalid characters
or
punctuation and tha it is not too long."

Can someone help me with this? It should be a simple update. The select
works fine and I am just trying to update one table with this
expression.
I
have heard everythingfrom cant do it to move all the info to the #1
position.
HELP!
 
G

Guest

Tom,

I have brought this down to the thread and back up again. This errors out at
the point of the Update query and where or what I am putting in the "field,
table, and Updateto" colunms. For some reason it just wont take what I am
putting into it.

One guy told me that the filed is my expression. That I beleive is correct,
the "table" line is where I am sending my data to (the target table)and not
the table from where my field is from. He also said to put my
tablename.fieldname in the updateto line. I believe that is correct. So
playing with everything from expressions to positions etc I am all out of
options. This has to be something very simple that I am overlooking. Here is
the
SQL without the expressions.

UPDATE dbo_tblSaaDocument RIGHT JOIN (dbo_tblObligationType INNER JOIN
(dbo_TblProductVersion INNER JOIN (DEV_dbo_TblProduct RIGHT JOIN
dbo_TblProduct ON DEV_dbo_TblProduct.ProductId = dbo_TblProduct.ProductId) ON
dbo_TblProductVersion.ProductId = dbo_TblProduct.ProductId) ON
dbo_tblObligationType.ObligationTypeID = dbo_TblProduct.ObligationTypeID) ON
dbo_tblSaaDocument.SaaDocumentID = dbo_tblObligationType.SaaDocumentID SET
dbo_TblProduct.ProductId = [DEV_dbo_TblProduct].[ProductId],
dbo_TblProduct.StateAbbr = [DEV_dbo_TblProduct].[stateabbr],
dbo_TblProductVersion.BondAmtMin = [DEV_dbo_TblProduct].[BondAmtMin],
dbo_tblObligationType.ProductLine = [DEV_dbo_TblProduct].[ProductLine],
dbo_TblProductVersion.BondAmtStd = [DEV_dbo_TblProduct].[BondAmtStd],
dbo_TblProductVersion.BondAmtMax = [DEV_dbo_TblProduct].[BondAmtMax],
dbo_tblObligationType.BondType = [DEV_dbo_TblProduct].[BondType],
dbo_TblProductVersion.BondTermMonths = [DEV_dbo_TblProduct].[BondTermMonths],
dbo_TblProductVersion.CancelDays = [DEV_dbo_TblProduct].[CancelDays],
dbo_TblProduct.ObligationTypeID = [DEV_dbo_TblProduct].[ObligationTypeID],
dbo_tblObligationType.CategoryID = [DEV_dbo_TblProduct].[CategoryID],
dbo_TblProductVersion.BondExpirationDate =
[DEV_dbo_TblProduct].[BondExpirationDate], dbo_TblProduct.[Available Online]
= [DEV_dbo_TblProduct].[AvailableOnline],
dbo_TblProductVersion.MinCreditScore = [DEV_dbo_TblProduct].[MinCreditScore],
dbo_TblProductVersion.NewBusinessFormID = [DEV_dbo_TblProduct].[FormId],
dbo_TblProductVersion.BondEffectiveDate =
[DEV_dbo_TblProduct].[BondEffectiveDate], dbo_tblSaaDocument.ClassCode =
[DEV_dbo_TblProduct].[ClassCode], dbo_TblProductVersion.RiskType =
[DEV_dbo_TblProduct].[RiskType], dbo_TblProductVersion.RateType =
[DEV_dbo_TblProduct].[RateType], dbo_TblProductVersion.RenewalMethod =
[DEV_dbo_TblProduct].[RenewalMethod], dbo_TblProductVersion.RateCode =
[DEV_dbo_TblProduct].[RateCode], dbo_TblProduct.BondObligationDescription =
[DEV_dbo_TblProduct].[BondObligationDescription], dbo_TblProduct.ObligeeId =
[DEV_dbo_TblProduct].[ObligeeID], dbo_TblProductVersion.SpecialInstructions =
[DEV_dbo_TblProduct].[SpecialInstructions]
WHERE (((DEV_dbo_TblProduct.ProductId) Is Not Null)) OR
(((dbo_TblProduct.ProductId)<>[dbo_tblProduct].[ProductId]) AND
((dbo_TblProduct.StateAbbr)<>[dbo_tblProduct].[StateAbbr]) AND
((dbo_TblProductVersion.BondAmtMin)<>[dbo_TblProductVersion].[BondAmtMin]))
OR (((dbo_tblObligationType.ProductLine) Not Like
[dbo_tblObligationType].[ProductLine]) AND
((dbo_TblProductVersion.BondAmtStd)<>[dbo_TblProductVersion].[BondAmtStd])
AND
((dbo_TblProductVersion.BondAmtMax)<>[dbo_TblProductVersion].[BondAmtmax]))
OR (((dbo_tblObligationType.BondType) Not Like
[dbo_tblObligationType].[BondType]) AND
((dbo_TblProductVersion.BondTermMonths)<>[dbo_TblProductVersion].[BondTermMonths])
AND
((dbo_TblProductVersion.CancelDays)<>[dbo_TblProductVersion].[CancelDays])
AND ((dbo_TblProduct.ObligationTypeID)<>[dbo_TblProduct].[ObligationTypeID]))
OR (((dbo_tblObligationType.CategoryID) Not Like
[dbo_tblObligationType].[CategoryID]) AND
((dbo_TblProductVersion.BondExpirationDate)<>[dbo_TblProductVersion].[BondExpirationDate])
AND ((dbo_TblProduct.[Available Online])<>[dbo_TblProduct].[Available
Online]) AND
((dbo_TblProductVersion.MinCreditScore)<>[dbo_TblProductVersion].[MinCreditScore]))
OR
(((dbo_TblProductVersion.NewBusinessFormID)<>[dbo_TblProductVersion].[NewBusinessFormID])
AND
((dbo_TblProductVersion.BondEffectiveDate)<>[dbo_TblProductVersion].[BondEffectiveDate])
AND ((dbo_tblSaaDocument.ClassCode)<>[dbo_tblSaaDocument].[ClassCode]) AND
((dbo_TblProductVersion.RiskType)<>[dbo_TblProductVersion].[RiskType])) OR
(((dbo_TblProductVersion.RateType)<>[dbo_TblProductVersion].[RateType]) AND
((dbo_TblProductVersion.RenewalMethod)<>[dbo_TblProductVersion].[RenewalMethod])
AND ((dbo_TblProductVersion.RateCode)<>[dbo_TblProductVersion].[RateCode])
AND
((dbo_TblProduct.BondObligationDescription)<>[dbo_TblProduct].[BondObligationDescription]))
OR (((dbo_TblProduct.ObligeeId)<>[dbo_TblProduct].[ObligeeId]) AND
((dbo_TblProductVersion.SpecialInstructions)<>[dbo_TblProductVersion].[SpecialInstructions]))
WITH OWNERACCESS OPTION;



Tom Ellison said:
Dear Troy:

Please post the SQL of your entire query. I'll look at it and try to find
an error.

Alternatively, remove portions of the query till you find where the error
is. Once you know where it is, fixing it is relatively easy.

Tom Ellison


troy said:
Thank you for your help. I get a syntax error with this. It seems my
expression worked in the select query and the append query that I did. It
also worked up to the point until I made it an pdate query. That is where
the
problem is (I think?) in the update portion of this mess. Any additional
ideas would be appreciated. I have received approx 10 different responses
and
getting closer everytime. I really appreciate everyones help in helping me
get through this. My time limit is almost up and I really need to get on
the
road with this thing. Thanks again

Tom Ellison said:
Dear Troy:

I think you're so, so close.

When you test the Attachments column, you use the keyword "True" in the
test
(without the quotes!). If you are setting another yes/no column's value,
use True and False, not "Y" and "N".

This thing:

dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]

Your use of square brackets is not balanced, and probably not needed.
Parens are also not balanced. Each left bracket or paren must be
balanced
by a right one. How about:

dbo_tblproductversion.IIf(dbo_tblproductversion.eandoflag = true, true,
false)

I leave testing the spelling of your table and column names to you.

Tom Ellison


I have been working on this for two days and can not find a solution. It
works perfectly as an select and Append query but not as an update
query.

In a nutshell:

I have a query (select) with 5 tables. One of the tables is a target
table
and the other 4 are source tables. In 3 of the fields I have this
expression..
Attachments: IIf(dbo_tblProductversion.Attachments=True,"Y","N")

I have this because these fields are Y/N datatypes.

I am tryig to update these three fields (different names of course)with
the
same expressions. I want them and other fileds (approx 15) to update
into
my
target table.
I am now ready for my update table and selct it. When I add this
expression
it will not allow me to select the table where this expression came
from
nor
will it allow me to add in my update to info. I get the following error
along
with trying to run the update query..

"dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]is
not a valid name. Make sure that it does not include invalid characters
or
punctuation and tha it is not too long."

Can someone help me with this? It should be a simple update. The select
works fine and I am just trying to update one table with this
expression.
I
have heard everythingfrom cant do it to move all the info to the #1
position.
HELP!
 
T

Tom Ellison

Dear Troy:

I reproduce your query here, edited in several ways:

1. Removed unnecessary parens and brackets

2. Used aliases for table names

3. added white space to my preferences

UPDATE dbo_tblSaaDocument S
RIGHT JOIN (dbo_tblObligationType O
INNER JOIN (dbo_TblProductVersion P
INNER JOIN (DEV_dbo_TblProduct D
RIGHT JOIN dbo_TblProduct R
ON D.ProductId = R.ProductId)
ON P.ProductId = R.ProductId)
ON O.ObligationTypeID = R.ObligationTypeID)
ON S.SaaDocumentID = O.SaaDocumentID
SET R.ProductId = D.ProductId,
R.StateAbbr = D.stateabbr,
P.BondAmtMin = D.BondAmtMin,
O.ProductLine = D.ProductLine,
P.BondAmtStd = D.BondAmtStd,
P.BondAmtMax = D.BondAmtMax,
O.BondType = D.BondType,
P.BondTermMonths = D.BondTermMonths,
P.CancelDays = D.CancelDays,
R.ObligationTypeID = D.ObligationTypeID,
O.CategoryID = D.CategoryID,
P.BondExpirationDate = D.BondExpirationDate,
R.[Available Online] = D.AvailableOnline,
P.MinCreditScore = D.MinCreditScore,
P.NewBusinessFormID = D.FormId,
P.BondEffectiveDate = D.BondEffectiveDate,
S.ClassCode = D.ClassCode,
P.RiskType = D.RiskType,
P.RateType = D.RateType,
P.RenewalMethod = D.RenewalMethod,
P.RateCode = D.RateCode,
R.BondObligationDescription = D.BondObligationDescription,
R.ObligeeId = D.ObligeeID,
P.SpecialInstructions = D.SpecialInstructions
WHERE D.ProductId Is Not Null
OR (R.ProductId <> R.ProductId
AND R.StateAbbr <> R.StateAbbr
AND P.BondAmtMin <> P.BondAmtMin)
OR (O.ProductLine Not Like O.ProductLine
AND P.BondAmtStd <> P.BondAmtStd
AND P.BondAmtMax <> P.BondAmtmax)
OR (O.BondType Not Like O.BondType
AND P.BondTermMonths <> P.BondTermMonths
AND P.CancelDays <> P.CancelDays
AND R.ObligationTypeID <> R.ObligationTypeID)
OR (O.CategoryID Not Like O.CategoryID
AND P.BondExpirationDate <> P.BondExpirationDate
AND R.[Available Online] <> R.[Available Online]
AND P.MinCreditScore <> P.MinCreditScore)
OR (P.NewBusinessFormID <> P.NewBusinessFormID
AND P.BondEffectiveDate <> P.BondEffectiveDate
AND S.ClassCode <> S.ClassCode
AND P.RiskType <> P.RiskType)
OR (P.RateType <> P.[RateType]
AND P.RenewalMethod <> P.RenewalMethod
AND P.RateCode <> P.RateCode
AND R.BondObligationDescription <> R.BondObligationDescription)
OR (R.ObligeeId <> R.ObligeeId
AND P.SpecialInstructions <> P.SpecialInstructions)
WITH OWNERACCESS OPTION;

The query is updating 5 tables from a 6th table.

An observation here. The WHERE clause contains numerous places like:

R.ProductId <> R.ProductId

This is never true. This means the entire section between ORs could just be
removed. I suspect there's something wrong with your logic.

Just for an experiment, remove the entire second half of the query,
everything starting with WHERE. Do all your experimenting in a COPY of the
database. Don't destroy your only copy of the data!!!

Is there still an error? Remove half the SET clause. Still an error?
Remove some more. At what point does it start working?

There are numerous apparent logic errors in the query. I wouldn't know
where to start, except to point out that a statement "X <> X" is not useful.

Tom Ellison



troy said:
Tom,

I have brought this down to the thread and back up again. This errors out
at
the point of the Update query and where or what I am putting in the
"field,
table, and Updateto" colunms. For some reason it just wont take what I am
putting into it.

One guy told me that the filed is my expression. That I beleive is
correct,
the "table" line is where I am sending my data to (the target table)and
not
the table from where my field is from. He also said to put my
tablename.fieldname in the updateto line. I believe that is correct. So
playing with everything from expressions to positions etc I am all out of
options. This has to be something very simple that I am overlooking. Here
is
the
SQL without the expressions.

UPDATE dbo_tblSaaDocument RIGHT JOIN (dbo_tblObligationType INNER JOIN
(dbo_TblProductVersion INNER JOIN (DEV_dbo_TblProduct RIGHT JOIN
dbo_TblProduct ON DEV_dbo_TblProduct.ProductId = dbo_TblProduct.ProductId)
ON
dbo_TblProductVersion.ProductId = dbo_TblProduct.ProductId) ON
dbo_tblObligationType.ObligationTypeID = dbo_TblProduct.ObligationTypeID)
ON
dbo_tblSaaDocument.SaaDocumentID = dbo_tblObligationType.SaaDocumentID SET
dbo_TblProduct.ProductId = [DEV_dbo_TblProduct].[ProductId],
dbo_TblProduct.StateAbbr = [DEV_dbo_TblProduct].[stateabbr],
dbo_TblProductVersion.BondAmtMin = [DEV_dbo_TblProduct].[BondAmtMin],
dbo_tblObligationType.ProductLine = [DEV_dbo_TblProduct].[ProductLine],
dbo_TblProductVersion.BondAmtStd = [DEV_dbo_TblProduct].[BondAmtStd],
dbo_TblProductVersion.BondAmtMax = [DEV_dbo_TblProduct].[BondAmtMax],
dbo_tblObligationType.BondType = [DEV_dbo_TblProduct].[BondType],
dbo_TblProductVersion.BondTermMonths =
[DEV_dbo_TblProduct].[BondTermMonths],
dbo_TblProductVersion.CancelDays = [DEV_dbo_TblProduct].[CancelDays],
dbo_TblProduct.ObligationTypeID = [DEV_dbo_TblProduct].[ObligationTypeID],
dbo_tblObligationType.CategoryID = [DEV_dbo_TblProduct].[CategoryID],
dbo_TblProductVersion.BondExpirationDate =
[DEV_dbo_TblProduct].[BondExpirationDate], dbo_TblProduct.[Available
Online]
= [DEV_dbo_TblProduct].[AvailableOnline],
dbo_TblProductVersion.MinCreditScore =
[DEV_dbo_TblProduct].[MinCreditScore],
dbo_TblProductVersion.NewBusinessFormID = [DEV_dbo_TblProduct].[FormId],
dbo_TblProductVersion.BondEffectiveDate =
[DEV_dbo_TblProduct].[BondEffectiveDate], dbo_tblSaaDocument.ClassCode =
[DEV_dbo_TblProduct].[ClassCode], dbo_TblProductVersion.RiskType =
[DEV_dbo_TblProduct].[RiskType], dbo_TblProductVersion.RateType =
[DEV_dbo_TblProduct].[RateType], dbo_TblProductVersion.RenewalMethod =
[DEV_dbo_TblProduct].[RenewalMethod], dbo_TblProductVersion.RateCode =
[DEV_dbo_TblProduct].[RateCode], dbo_TblProduct.BondObligationDescription
=
[DEV_dbo_TblProduct].[BondObligationDescription], dbo_TblProduct.ObligeeId
=
[DEV_dbo_TblProduct].[ObligeeID],
dbo_TblProductVersion.SpecialInstructions =
[DEV_dbo_TblProduct].[SpecialInstructions]
WHERE (((DEV_dbo_TblProduct.ProductId) Is Not Null)) OR
(((dbo_TblProduct.ProductId)<>[dbo_tblProduct].[ProductId]) AND
((dbo_TblProduct.StateAbbr)<>[dbo_tblProduct].[StateAbbr]) AND
((dbo_TblProductVersion.BondAmtMin)<>[dbo_TblProductVersion].[BondAmtMin]))
OR (((dbo_tblObligationType.ProductLine) Not Like
[dbo_tblObligationType].[ProductLine]) AND
((dbo_TblProductVersion.BondAmtStd)<>[dbo_TblProductVersion].[BondAmtStd])
AND
((dbo_TblProductVersion.BondAmtMax)<>[dbo_TblProductVersion].[BondAmtmax]))
OR (((dbo_tblObligationType.BondType) Not Like
[dbo_tblObligationType].[BondType]) AND
((dbo_TblProductVersion.BondTermMonths)<>[dbo_TblProductVersion].[BondTermMonths])
AND
((dbo_TblProductVersion.CancelDays)<>[dbo_TblProductVersion].[CancelDays])
AND
((dbo_TblProduct.ObligationTypeID)<>[dbo_TblProduct].[ObligationTypeID]))
OR (((dbo_tblObligationType.CategoryID) Not Like
[dbo_tblObligationType].[CategoryID]) AND
((dbo_TblProductVersion.BondExpirationDate)<>[dbo_TblProductVersion].[BondExpirationDate])
AND ((dbo_TblProduct.[Available Online])<>[dbo_TblProduct].[Available
Online]) AND
((dbo_TblProductVersion.MinCreditScore)<>[dbo_TblProductVersion].[MinCreditScore]))
OR
(((dbo_TblProductVersion.NewBusinessFormID)<>[dbo_TblProductVersion].[NewBusinessFormID])
AND
((dbo_TblProductVersion.BondEffectiveDate)<>[dbo_TblProductVersion].[BondEffectiveDate])
AND ((dbo_tblSaaDocument.ClassCode)<>[dbo_tblSaaDocument].[ClassCode]) AND
((dbo_TblProductVersion.RiskType)<>[dbo_TblProductVersion].[RiskType])) OR
(((dbo_TblProductVersion.RateType)<>[dbo_TblProductVersion].[RateType])
AND
((dbo_TblProductVersion.RenewalMethod)<>[dbo_TblProductVersion].[RenewalMethod])
AND ((dbo_TblProductVersion.RateCode)<>[dbo_TblProductVersion].[RateCode])
AND
((dbo_TblProduct.BondObligationDescription)<>[dbo_TblProduct].[BondObligationDescription]))
OR (((dbo_TblProduct.ObligeeId)<>[dbo_TblProduct].[ObligeeId]) AND
((dbo_TblProductVersion.SpecialInstructions)<>[dbo_TblProductVersion].[SpecialInstructions]))
WITH OWNERACCESS OPTION;



Tom Ellison said:
Dear Troy:

Please post the SQL of your entire query. I'll look at it and try to
find
an error.

Alternatively, remove portions of the query till you find where the error
is. Once you know where it is, fixing it is relatively easy.

Tom Ellison


troy said:
Thank you for your help. I get a syntax error with this. It seems my
expression worked in the select query and the append query that I did.
It
also worked up to the point until I made it an pdate query. That is
where
the
problem is (I think?) in the update portion of this mess. Any
additional
ideas would be appreciated. I have received approx 10 different
responses
and
getting closer everytime. I really appreciate everyones help in helping
me
get through this. My time limit is almost up and I really need to get
on
the
road with this thing. Thanks again

:

Dear Troy:

I think you're so, so close.

When you test the Attachments column, you use the keyword "True" in
the
test
(without the quotes!). If you are setting another yes/no column's
value,
use True and False, not "Y" and "N".

This thing:

dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]

Your use of square brackets is not balanced, and probably not needed.
Parens are also not balanced. Each left bracket or paren must be
balanced
by a right one. How about:

dbo_tblproductversion.IIf(dbo_tblproductversion.eandoflag = true,
true,
false)

I leave testing the spelling of your table and column names to you.

Tom Ellison


I have been working on this for two days and can not find a solution.
It
works perfectly as an select and Append query but not as an update
query.

In a nutshell:

I have a query (select) with 5 tables. One of the tables is a target
table
and the other 4 are source tables. In 3 of the fields I have this
expression..
Attachments: IIf(dbo_tblProductversion.Attachments=True,"Y","N")

I have this because these fields are Y/N datatypes.

I am tryig to update these three fields (different names of
course)with
the
same expressions. I want them and other fileds (approx 15) to update
into
my
target table.
I am now ready for my update table and selct it. When I add this
expression
it will not allow me to select the table where this expression came
from
nor
will it allow me to add in my update to info. I get the following
error
along
with trying to run the update query..

"dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]is
not a valid name. Make sure that it does not include invalid
characters
or
punctuation and tha it is not too long."

Can someone help me with this? It should be a simple update. The
select
works fine and I am just trying to update one table with this
expression.
I
have heard everythingfrom cant do it to move all the info to the #1
position.
HELP!
 
G

Guest

Thank you very much for your time and effort. For some reason it still will
not work. I took your SQL and just tried to add on filed with the expression
and I received the same error. It is a simple expression that works time and
time again.
Attachments: IIf(dbo_tblProductversion.Attachments=-1,"Y","N"), but for some
reason it will not allow me to continue adding the table where this
expression came from. Only in the update query. Do you believe this? Thanks
agai for all your time. I will mess with it somemore. It is something I hae
to get done. Take care

Tom Ellison said:
Dear Troy:

I reproduce your query here, edited in several ways:

1. Removed unnecessary parens and brackets

2. Used aliases for table names

3. added white space to my preferences

UPDATE dbo_tblSaaDocument S
RIGHT JOIN (dbo_tblObligationType O
INNER JOIN (dbo_TblProductVersion P
INNER JOIN (DEV_dbo_TblProduct D
RIGHT JOIN dbo_TblProduct R
ON D.ProductId = R.ProductId)
ON P.ProductId = R.ProductId)
ON O.ObligationTypeID = R.ObligationTypeID)
ON S.SaaDocumentID = O.SaaDocumentID
SET R.ProductId = D.ProductId,
R.StateAbbr = D.stateabbr,
P.BondAmtMin = D.BondAmtMin,
O.ProductLine = D.ProductLine,
P.BondAmtStd = D.BondAmtStd,
P.BondAmtMax = D.BondAmtMax,
O.BondType = D.BondType,
P.BondTermMonths = D.BondTermMonths,
P.CancelDays = D.CancelDays,
R.ObligationTypeID = D.ObligationTypeID,
O.CategoryID = D.CategoryID,
P.BondExpirationDate = D.BondExpirationDate,
R.[Available Online] = D.AvailableOnline,
P.MinCreditScore = D.MinCreditScore,
P.NewBusinessFormID = D.FormId,
P.BondEffectiveDate = D.BondEffectiveDate,
S.ClassCode = D.ClassCode,
P.RiskType = D.RiskType,
P.RateType = D.RateType,
P.RenewalMethod = D.RenewalMethod,
P.RateCode = D.RateCode,
R.BondObligationDescription = D.BondObligationDescription,
R.ObligeeId = D.ObligeeID,
P.SpecialInstructions = D.SpecialInstructions
WHERE D.ProductId Is Not Null
OR (R.ProductId <> R.ProductId
AND R.StateAbbr <> R.StateAbbr
AND P.BondAmtMin <> P.BondAmtMin)
OR (O.ProductLine Not Like O.ProductLine
AND P.BondAmtStd <> P.BondAmtStd
AND P.BondAmtMax <> P.BondAmtmax)
OR (O.BondType Not Like O.BondType
AND P.BondTermMonths <> P.BondTermMonths
AND P.CancelDays <> P.CancelDays
AND R.ObligationTypeID <> R.ObligationTypeID)
OR (O.CategoryID Not Like O.CategoryID
AND P.BondExpirationDate <> P.BondExpirationDate
AND R.[Available Online] <> R.[Available Online]
AND P.MinCreditScore <> P.MinCreditScore)
OR (P.NewBusinessFormID <> P.NewBusinessFormID
AND P.BondEffectiveDate <> P.BondEffectiveDate
AND S.ClassCode <> S.ClassCode
AND P.RiskType <> P.RiskType)
OR (P.RateType <> P.[RateType]
AND P.RenewalMethod <> P.RenewalMethod
AND P.RateCode <> P.RateCode
AND R.BondObligationDescription <> R.BondObligationDescription)
OR (R.ObligeeId <> R.ObligeeId
AND P.SpecialInstructions <> P.SpecialInstructions)
WITH OWNERACCESS OPTION;

The query is updating 5 tables from a 6th table.

An observation here. The WHERE clause contains numerous places like:

R.ProductId <> R.ProductId

This is never true. This means the entire section between ORs could just be
removed. I suspect there's something wrong with your logic.

Just for an experiment, remove the entire second half of the query,
everything starting with WHERE. Do all your experimenting in a COPY of the
database. Don't destroy your only copy of the data!!!

Is there still an error? Remove half the SET clause. Still an error?
Remove some more. At what point does it start working?

There are numerous apparent logic errors in the query. I wouldn't know
where to start, except to point out that a statement "X <> X" is not useful.

Tom Ellison



troy said:
Tom,

I have brought this down to the thread and back up again. This errors out
at
the point of the Update query and where or what I am putting in the
"field,
table, and Updateto" colunms. For some reason it just wont take what I am
putting into it.

One guy told me that the filed is my expression. That I beleive is
correct,
the "table" line is where I am sending my data to (the target table)and
not
the table from where my field is from. He also said to put my
tablename.fieldname in the updateto line. I believe that is correct. So
playing with everything from expressions to positions etc I am all out of
options. This has to be something very simple that I am overlooking. Here
is
the
SQL without the expressions.

UPDATE dbo_tblSaaDocument RIGHT JOIN (dbo_tblObligationType INNER JOIN
(dbo_TblProductVersion INNER JOIN (DEV_dbo_TblProduct RIGHT JOIN
dbo_TblProduct ON DEV_dbo_TblProduct.ProductId = dbo_TblProduct.ProductId)
ON
dbo_TblProductVersion.ProductId = dbo_TblProduct.ProductId) ON
dbo_tblObligationType.ObligationTypeID = dbo_TblProduct.ObligationTypeID)
ON
dbo_tblSaaDocument.SaaDocumentID = dbo_tblObligationType.SaaDocumentID SET
dbo_TblProduct.ProductId = [DEV_dbo_TblProduct].[ProductId],
dbo_TblProduct.StateAbbr = [DEV_dbo_TblProduct].[stateabbr],
dbo_TblProductVersion.BondAmtMin = [DEV_dbo_TblProduct].[BondAmtMin],
dbo_tblObligationType.ProductLine = [DEV_dbo_TblProduct].[ProductLine],
dbo_TblProductVersion.BondAmtStd = [DEV_dbo_TblProduct].[BondAmtStd],
dbo_TblProductVersion.BondAmtMax = [DEV_dbo_TblProduct].[BondAmtMax],
dbo_tblObligationType.BondType = [DEV_dbo_TblProduct].[BondType],
dbo_TblProductVersion.BondTermMonths =
[DEV_dbo_TblProduct].[BondTermMonths],
dbo_TblProductVersion.CancelDays = [DEV_dbo_TblProduct].[CancelDays],
dbo_TblProduct.ObligationTypeID = [DEV_dbo_TblProduct].[ObligationTypeID],
dbo_tblObligationType.CategoryID = [DEV_dbo_TblProduct].[CategoryID],
dbo_TblProductVersion.BondExpirationDate =
[DEV_dbo_TblProduct].[BondExpirationDate], dbo_TblProduct.[Available
Online]
= [DEV_dbo_TblProduct].[AvailableOnline],
dbo_TblProductVersion.MinCreditScore =
[DEV_dbo_TblProduct].[MinCreditScore],
dbo_TblProductVersion.NewBusinessFormID = [DEV_dbo_TblProduct].[FormId],
dbo_TblProductVersion.BondEffectiveDate =
[DEV_dbo_TblProduct].[BondEffectiveDate], dbo_tblSaaDocument.ClassCode =
[DEV_dbo_TblProduct].[ClassCode], dbo_TblProductVersion.RiskType =
[DEV_dbo_TblProduct].[RiskType], dbo_TblProductVersion.RateType =
[DEV_dbo_TblProduct].[RateType], dbo_TblProductVersion.RenewalMethod =
[DEV_dbo_TblProduct].[RenewalMethod], dbo_TblProductVersion.RateCode =
[DEV_dbo_TblProduct].[RateCode], dbo_TblProduct.BondObligationDescription
=
[DEV_dbo_TblProduct].[BondObligationDescription], dbo_TblProduct.ObligeeId
=
[DEV_dbo_TblProduct].[ObligeeID],
dbo_TblProductVersion.SpecialInstructions =
[DEV_dbo_TblProduct].[SpecialInstructions]
WHERE (((DEV_dbo_TblProduct.ProductId) Is Not Null)) OR
(((dbo_TblProduct.ProductId)<>[dbo_tblProduct].[ProductId]) AND
((dbo_TblProduct.StateAbbr)<>[dbo_tblProduct].[StateAbbr]) AND
((dbo_TblProductVersion.BondAmtMin)<>[dbo_TblProductVersion].[BondAmtMin]))
OR (((dbo_tblObligationType.ProductLine) Not Like
[dbo_tblObligationType].[ProductLine]) AND
((dbo_TblProductVersion.BondAmtStd)<>[dbo_TblProductVersion].[BondAmtStd])
AND
((dbo_TblProductVersion.BondAmtMax)<>[dbo_TblProductVersion].[BondAmtmax]))
OR (((dbo_tblObligationType.BondType) Not Like
[dbo_tblObligationType].[BondType]) AND
((dbo_TblProductVersion.BondTermMonths)<>[dbo_TblProductVersion].[BondTermMonths])
AND
((dbo_TblProductVersion.CancelDays)<>[dbo_TblProductVersion].[CancelDays])
AND
((dbo_TblProduct.ObligationTypeID)<>[dbo_TblProduct].[ObligationTypeID]))
OR (((dbo_tblObligationType.CategoryID) Not Like
[dbo_tblObligationType].[CategoryID]) AND
((dbo_TblProductVersion.BondExpirationDate)<>[dbo_TblProductVersion].[BondExpirationDate])
AND ((dbo_TblProduct.[Available Online])<>[dbo_TblProduct].[Available
Online]) AND
((dbo_TblProductVersion.MinCreditScore)<>[dbo_TblProductVersion].[MinCreditScore]))
OR
(((dbo_TblProductVersion.NewBusinessFormID)<>[dbo_TblProductVersion].[NewBusinessFormID])
AND
((dbo_TblProductVersion.BondEffectiveDate)<>[dbo_TblProductVersion].[BondEffectiveDate])
AND ((dbo_tblSaaDocument.ClassCode)<>[dbo_tblSaaDocument].[ClassCode]) AND
((dbo_TblProductVersion.RiskType)<>[dbo_TblProductVersion].[RiskType])) OR
(((dbo_TblProductVersion.RateType)<>[dbo_TblProductVersion].[RateType])
AND
((dbo_TblProductVersion.RenewalMethod)<>[dbo_TblProductVersion].[RenewalMethod])
AND ((dbo_TblProductVersion.RateCode)<>[dbo_TblProductVersion].[RateCode])
AND
((dbo_TblProduct.BondObligationDescription)<>[dbo_TblProduct].[BondObligationDescription]))
OR (((dbo_TblProduct.ObligeeId)<>[dbo_TblProduct].[ObligeeId]) AND
((dbo_TblProductVersion.SpecialInstructions)<>[dbo_TblProductVersion].[SpecialInstructions]))
WITH OWNERACCESS OPTION;



Tom Ellison said:
Dear Troy:

Please post the SQL of your entire query. I'll look at it and try to
find
an error.

Alternatively, remove portions of the query till you find where the error
is. Once you know where it is, fixing it is relatively easy.

Tom Ellison


Thank you for your help. I get a syntax error with this. It seems my
expression worked in the select query and the append query that I did.
It
also worked up to the point until I made it an pdate query. That is
where
the
problem is (I think?) in the update portion of this mess. Any
additional
ideas would be appreciated. I have received approx 10 different
responses
and
getting closer everytime. I really appreciate everyones help in helping
me
get through this. My time limit is almost up and I really need to get
on
the
road with this thing. Thanks again

:

Dear Troy:

I think you're so, so close.

When you test the Attachments column, you use the keyword "True" in
the
test
(without the quotes!). If you are setting another yes/no column's
value,
use True and False, not "Y" and "N".

This thing:

dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]

Your use of square brackets is not balanced, and probably not needed.
Parens are also not balanced. Each left bracket or paren must be
balanced
by a right one. How about:

dbo_tblproductversion.IIf(dbo_tblproductversion.eandoflag = true,
true,
false)

I leave testing the spelling of your table and column names to you.

Tom Ellison


I have been working on this for two days and can not find a solution.
It
works perfectly as an select and Append query but not as an update
query.

In a nutshell:

I have a query (select) with 5 tables. One of the tables is a target
table
and the other 4 are source tables. In 3 of the fields I have this
expression..
Attachments: IIf(dbo_tblProductversion.Attachments=True,"Y","N")

I have this because these fields are Y/N datatypes.

I am tryig to update these three fields (different names of
course)with
the
same expressions. I want them and other fileds (approx 15) to update
into
my
target table.
I am now ready for my update table and selct it. When I add this
expression
it will not allow me to select the table where this expression came
from
nor
will it allow me to add in my update to info. I get the following
error
along
with trying to run the update query..

"dbo_tblproductversion.IIF(([dbo_tblproductversion]].[[eandoflag]=true,"y","n")]is
not a valid name. Make sure that it does not include invalid
characters
or
punctuation and tha it is not too long."
 
V

Van T. Dinh

I explained the problem with the Update SQL in the orginal thread: you are
doing a Boolean-value comparison on the Field [Attachments] and then
assigning a Text value to the SAME Field. The Field [Attachments] canNOT be
of Boolean type and Text type. Thus, the database engine will give you an
error every time.

In the Select SQL, the IIf expression is a Calculated Value only (not being
forced back to the Table Field) so its type is not important.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top