Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default What is the SQL syntax to concatenate 2 fields in VBA for Excel

Hi,

I have successfully employed the following syntax in MS Access but cannot
get it to work running a SQL query from within Visual Basic.

SELECT GLAFS.ACCTID, GLAMF.ACCTDESC, Left([GLAMF]![ACSEGVAL01],4) &
Left([GLAMF]![ACSEGVAL03],3) AS AcctGroup,
GLAFS.OPENBAL+GLAFS.NETPERD1+GLAFS.NETPERD2+GLAFS. NETPERD3+GLAFS.NETPERD4+GLAFS.NETPERD5+GLAFS.NETPE RD6 AS Expr1, GLAFS.NETPERD6
FROM GLAFS RIGHT JOIN GLAMF ON GLAFS.ACCTID = GLAMF.ACCTID
WHERE (((GLAFS.FSCSDSG)='1') AND ((GLAFS.FSCSYR)='2006') AND
((GLAMF.ACCTTYPE)='I') AND ((GLAFS.CURNTYPE)='F'))
ORDER BY GLAFS.ACCTID;

The problem seems to be with the AcctGroup field and the "&" character where
I am trying to concatenate sections of 2 text fields. There are some
variables in the VB statement which looks like this:

strSqlGLTrialBalance = "SELECT " _
& "GLAFS.ACCTID As AccountID, left(GLAFS.ACSEGVAL01),4) &
Left((GLAMF.ACSEGVAL03),3) AS AcctGroup, GLAMF.ACCTDESC As Description, " _
& strSqlPeriodBalance & strSqlMovement & "FROM GLAFS " _
& "RIGHT JOIN GLAMF ON GLAFS.ACCTID = GLAMF.ACCTID " _
& "WHERE GLAFS.FSCSDSG='" & strActualBudget & "' AND GLAFS.FSCSYR='" &
strYear & "' " _
& "AND GLAMF.ACCTTYPE" & strAccountTypeCondition & " AND
GLAFS.CURNTYPE='F' " _
& strSqlWHEREClause _
& "ORDER BY GLAFS.ACCTID"


If anyone can assist, I would be really grateful!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I concatenate two date fields fetter Excel Discussion (Misc queries) 2 May 4th 10 05:57 PM
syntax to concatenate two named ranges? ker_01 Excel Discussion (Misc queries) 2 March 22nd 10 10:16 PM
How do i concatenate two date fields. J9 New Users to Excel 1 September 8th 09 05:28 AM
How to CONCATENATE 50 fields in Excel table into SQL Insert State will~ Excel Discussion (Misc queries) 3 February 28th 08 08:58 PM
Cannot Concatenate fields using Query CJ Excel Discussion (Misc queries) 6 September 10th 07 04:32 AM


All times are GMT +1. The time now is 12:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"