Solved

SQL VIEW

Posted on 2013-01-17
7
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

688 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