Solved

SQL Statement

Posted on 2014-09-09
6
164 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
ID: 40312406
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
ID: 40312652
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
ID: 40313239
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
ID: 40314646
Hi,

the database is SQL anywhere 11.
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 40314788
Try changing the output line to

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

mlmcc
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access Query 4 46
SQL Query - Oracle 10g - Subract date from next data row 4 48
SQL query 4 47
VB.NET return row from SQL to DataSet and get column values ? 3 26
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
A short film showing how OnPage and Connectwise integration works.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

919 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

15 Experts available now in Live!

Get 1:1 Help Now