Solved

SQL VIEW

Posted on 2013-01-17
7
225 Views
Last Modified: 2013-01-17
Hi,

Im not used to working with SQL view. I am trying to put the condition

"SC" into field DR/CR

The SQL is

INSERT INTO [A1 - APAC Data] ( SEC, [WINNAR NO], LEDGER, [DR/CR], CCY, AMOUNT, [VALUE], [AGE BY VALUE], ENTRY_DATE, SFIELD_7, SFIELD_8, SFIELD_9, TRAN_CODE, GBP_EQUIV, [Root Cause] )
SELECT [1 - Import APAC].SEC, [1 - Import APAC].[WINNAR NO#], [1 - Import APAC].LEDGER, [1 - Import APAC].[DR/CR], [1 - Import APAC].CCY, [1 - Import APAC].AMOUNT, [1 - Import APAC].VALUE, Val(Replace([1 - Import APAC]![AGE BY VALUE]," days","",1)) AS Expr1, [1 - Import APAC].ENTRY_DATE, [1 - Import APAC].SFIELD_7, [1 - Import APAC].SFIELD_8, [1 - Import APAC].SFIELD_9, [1 - Import APAC].TRAN_CODE, [1 - Import APAC].GBP_EQUIV, [1 - Import APAC].[Root Cause]
FROM [1 - Import APAC];


Can anyone amend the code to include that condition?

Thanks
0
Comment
Question by:Seamus2626
  • 3
  • 3
7 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38787452
INSERT INTO [A1 - APAC Data] ( SEC, [WINNAR NO], LEDGER, [DR/CR], CCY, AMOUNT, [VALUE], [AGE BY VALUE], ENTRY_DATE, SFIELD_7, SFIELD_8, SFIELD_9, TRAN_CODE, GBP_EQUIV, [Root Cause] )
SELECT [1 - Import APAC].SEC, [1 - Import APAC].[WINNAR NO#], [1 - Import APAC].LEDGER, [1 - Import APAC].[DR/CR], [1 - Import APAC].CCY, [1 - Import APAC].AMOUNT, [1 - Import APAC].VALUE, Val(Replace([1 - Import APAC]![AGE BY VALUE]," days","",1)) AS Expr1, [1 - Import APAC].ENTRY_DATE, [1 - Import APAC].SFIELD_7, [1 - Import APAC].SFIELD_8, [1 - Import APAC].SFIELD_9, [1 - Import APAC].TRAN_CODE, [1 - Import APAC].GBP_EQUIV, [1 - Import APAC].[Root Cause]
FROM [1 - Import APAC]  WHERE [DR/CR] = "SC"

Open in new window

0
 

Author Closing Comment

by:Seamus2626
ID: 38787464
Thanks mbizup!

Seamus
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38787488
Glad to help!  

Cleaning the syntax a little:

INSERT INTO [A1 - APAC Data] ( SEC, [WINNAR NO], LEDGER, [DR/CR], CCY, AMOUNT, [VALUE], [AGE BY VALUE], ENTRY_DATE, SFIELD_7, SFIELD_8, SFIELD_9, TRAN_CODE, GBP_EQUIV, [Root Cause] )
SELECT Imp.SEC,  Imp.WINNAR NO#],  Imp.LEDGER, Imp.DR/CR],  Imp.CCY,  Imp.AMOUNT, Imp.VALUE, Val(Replace([1 -  Imp![AGE BY VALUE]," days","",1)) AS Expr1,  Imp.ENTRY_DATE,  Imp.SFIELD_7, Imp.SFIELD_8,  Imp.SFIELD_9,  Imp.TRAN_CODE, Imp.GBP_EQUIV,  Imp.[Root Cause]
FROM [1 - Import APAC] Imp WHERE  Imp.[DR/CR] = "SC"

Open in new window


Ideally all those field and table names should be changed to not include spaces or special characters.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Seamus2626
ID: 38787495
Why is that out of interest?

Thanks
0
 
LVL 26

Expert Comment

by:jerryb30
ID: 38787779
See this:
http://support.microsoft.com/kb/826763
Ideally, MS Access would catch all of these when naming fields, but it does not.  And, use of some of these 'reserved'  characters can be allowed by use of brackets. But they may not work in other databases and code, such as vba.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38787824
Sorry I missed your comment -  I got the email notif for Jerry's comment though.  :-)

Anyhow, just seconding what he said...

Not just for table and field names... but for variables, objects, etc.

Reserved words, spaces and special characters can cause real problems in code and queries.  Not only does your code etc look cleaner when you steer clear of them, but you can omit those brackets, and count it as one less thing to go wrong.

Most of the regulars here use the Reddick VBA (or similar) conventions for naming objects, fields.  Standards specific to Access are midway down the page:
http://www.xoc.net/standards/rvbanc.asp
0
 

Author Comment

by:Seamus2626
ID: 38787847
Okay, i see.

Thanks for the heads up guys
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Concatenating data within ACCESS table 3 20
putting an icon in a form 13 22
Help with SQl and UNION 7 16
Minus first query 1 6
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now