April 19, 2005 at 11:01 am
Can any tell me why I'm getting invalid column name error on this?
Invalid Column Name 'CHF'
INSERT INTO MasterDailyBalances
( [BalanceDate], [loan_id], [ScheduledBalance], [ArrearsCapital], [ArrearsInterest], [ArrearsCosts], [TotalClaim], [Currency], [LNRTotalClaimEUR], [AdditionalInterest])
SELECT getdate() AS BalanceDate, H3DESC AS loan_id, [H3PRBL]-[H3Pod]
AS ScheduledBalance, H3POD AS ArrearsCapital, H3IOD
AS ArrearsInterest, H3FOD
AS ArrearsCosts, (H3PRBL-H3POD)+H3POD+H3IOD+H3AIBL+HPTRCH.H3FOD
AS TotalClaim,
[H4CURR] AS Currency, (H3PRBL-H3POD+H3POD+H3IOD+H3AIBL+H3FOD)/1.5476
AS LNRTotalClaimEUR, dbo.HPTRCH.H3AIBL AS AdditionalInterest
FROM dbo.HPTRCH LEFT JOIN dbo.HPTRPM ON dbo.HPTRCH.H3SERL = dbo.HPTRPM.H4SERL
WHERE [H4CURR]= "CHF"
NewBe very grateful foe any help/advice
April 19, 2005 at 11:04 am
******************
Dinakar Nethi
Life is short. Enjoy it.
******************
April 19, 2005 at 11:08 am
Thats fixed it thanks
I copy and pasted from MS Access (too much to ask that products from the same family use the same sql I s'pose)
What does it mean then when the syntax turns red - this put me off trying the single quote??
April 19, 2005 at 11:50 am
red = string. as soon as you type a single quote anything typed after that becomes red until you close the single quote which marks the end of the string.
******************
Dinakar Nethi
Life is short. Enjoy it.
******************
April 19, 2005 at 2:39 pm
Thank you once again. My sanity is preserved
April 20, 2005 at 2:01 am
SET QUOTED_IDENTIFIER OFF allows you to use double quotes as well as single for strings but this is not usually a database default so needs to be included in your stored procedures to be safe.
April 20, 2005 at 3:47 am
It may also be set by the connecting client, so to be on the safe side, it's best to get into the habit of always using single quotes when denoting strings, never use double quotes.
Single quotes will also give you the nice colormarking, whereas doublequotes won't.
/Kenneth
April 20, 2005 at 3:53 am
Agreed, but sometimes it's useful, eg including a literal string in a constructed OPENQUERY(), eg :
SET @strCommand = "SELECT * FROM OPENQUERY(server, SELECT * FROM Database.dbo.Client WHERE Surname = '" + @NameWanted + "')"
April 20, 2005 at 5:36 am
Though, you'd still be missing the nice red colour
On the other hand, it's just as 'easy' to replace the double quotes with single
SET @strCommand = 'SELECT * FROM OPENQUERY(server, SELECT * FROM Database.dbo.Client WHERE Surname = ''' + @NameWanted + ''')'
However, it tends to be messy pretty quick when you have to escape singlequotes, so another option to 'keep it neat' might be to denote strings as usual with single quotes, and when necessary to place explicit singlequotes, use the CHAR() function for it... and still keep the syntax colouring
SET @strCommand = 'SELECT * FROM OPENQUERY(server, SELECT * FROM Database.dbo.Client WHERE Surname = ' + char(39) + @NameWanted + char(39) + ')'
/Kenneth
April 20, 2005 at 5:50 am
Thank you - much better. I'll do it that way (CHR(39)) in future. As you say, escaping quotes is messy and difficult to read so I prefer to avoid that.
April 20, 2005 at 9:04 am
I'm starting to get really peed off now. In the original statement how do I change it so the it asks:-
if [H4CURR]= 'CHF', then (H3PRBL-H3POD+H3POD+H3IOD+H3AIBL+H3FOD)/1.5476,else(H3PRBL-H3POD+H3POD+H3IOD+H3AIBL+H3FOD)
AS LNRTotalClaimEUR
April 20, 2005 at 9:10 am
(H3PRBL-H3POD+H3POD+H3IOD+H3AIBL+H3FOD) / (case when [H4CURR]= 'CHF', then 1.5476 else 1 end)
AS LNRTotalClaimEUR
hth
* Noel
April 20, 2005 at 9:15 am
You have a comma that should not be there :
(H3PRBL-H3POD+H3POD+H3IOD+H3AIBL+H3FOD) / (case when [H4CURR]= 'CHF' then 1.5476 else 1 end)
AS LNRTotalClaimEUR
April 20, 2005 at 9:20 am
Yep, you are right. I call it the cut and paste effect
* Noel
April 20, 2005 at 9:23 am
I seeeeeeeee.
You really have to spell it out to the system dontcha
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply