Solved

SQL Statement

Posted on 2014-09-09
6
163 Views
Last Modified: 2014-09-10
Hi,

I have the SQL statement below that’s works but puts ‘ ’ around the results of the column micros.mi_def.name_1 , how can I remove the ‘ ’ ?


Results:
1001011,'Fishcakes',21,3
1005009,'Angus Burger',11,1
1005019,'Bacon Burger',24,2
1006004,'Four Cheese',18,2

SQL:
SELECT item = micros.mi_def.obj_num, name = micros.mi_def.name_1, Sales = SUM(CONVERT(INT, (price_1_sls_ttl+price_2_sls_ttl+price_3_sls_ttl+price_4_sls_ttl))), Quantity = sum(price_1_sls_cnt+price_2_sls_cnt+price_3_sls_cnt+price_4_sls_cnt)
FROM micros.rest_status, micros.rvc_def, micros.dly_rvc_mi_ttl
right outer join micros.mi_def
where rvc_def.rvc_seq = dly_rvc_mi_ttl.rvc_seq
and mi_def.maj_grp_seq in (1,2,3)
and dly_rvc_mi_ttl.business_date = rest_status.business_date -1
GROUP BY micros.mi_def.maj_grp_seq, micros.mi_def.obj_num, micros.mi_def.name_1
ORDER BY item;
output to 'c:\export\test.001'
0
Comment
Question by:hellblazeruk
6 Comments
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
What database are you running against?

I suspect it is a setting in your database configuration to export text fields with quotes around them.

mlmcc
0
 
LVL 18

Expert Comment

by:vasto
Comment Utility
This is normal. The type of micros.mi_def.name_1 is varchar, string, text ( whatever is the type for string in your database) and the export will add ' to distinct the text from the other data. Actually this formatting is done by the command "output" and this is not a SQLServer command ( at leas not SQL92). Search for options for this command , may be there is a parameter , which will allow you to export the data without formatting
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
What database are you using please?

Your query has syntax issues, and while you state "it works" it may not be reliable.
1. There are 4 tables in the FROM clause, but only 2 join conditions in the WHERE clause (so there is a missing join condition)
2. you mix non-ANSI and ANSI join syntax, that is never good. Use only ANSI syntax.

FROM micros.rest_status
   , micros.rvc_def
   , micros.dly_rvc_mi_ttl
     RIGHT OUTER JOIN micros.mi_def --<< missing ???

WHERE rvc_def.rvc_seq = dly_rvc_mi_ttl.rvc_seq
      AND dly_rvc_mi_ttl.business_date = rest_status.business_date - 1

      AND mi_def.maj_grp_seq IN (1, 2, 3)

Open in new window

0
 

Author Comment

by:hellblazeruk
Comment Utility
Hi,

the database is SQL anywhere 11.
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
Comment Utility
Try changing the output line to

OUTPUT TO 'c:\export\test.001' FORMAT ASCII DELIMITED BY ',' QUOTE '';

mlmcc
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

16 Experts available now in Live!

Get 1:1 Help Now