SQL query - combining AND and OR
I am just tweaking a page here:
http://www.goodsafariguide.net/africanhorseback/index102.php
Basically just changing the nominations history part to just show nominations from 2013 and 2011, as some of the palces had too long a list of nominations.
So the original SQL query was:
SELECT NominationID, Category, Year, Finalist, Winner, LodgeID FROM nominations WHERE LodgeID = 288 ORDER BY Year DESC, CATEGORY ASC
So I want it to now display nominations for that LodgeID, but just for 2011 and 2013, which I thought should just be:
SELECT NominationID, Category, Year, Finalist, Winner, LodgeID FROM nominations WHERE LodgeID = 288 AND (Year='2013' OR '2011') ORDER BY Year DESC, CATEGORY ASC
But that isn't working. I've tried a few variations, with and without the inverted commas, but can't seem to get it.
Any suggestions?
Try this:
SELECT NominationID, Category, Year, Finalist, Winner, LodgeID FROM nominations WHERE (Year='2013' OR Year='2011') AND LodgeID = '288' ORDER BY Year DESC, CATEGORY ASC
if you wanted a run of years like 2011 , 2012 and 2013 you could use:
SELECT NominationID, Category, Year, Finalist, Winner, LodgeID FROM nominations WHERE Year BETWEEN '2011' AND '2013' AND LodgeID = '288' ORDER BY Year DESC, CATEGORY ASC
Similar Messages
-
Hi all,
I think I'm being really stupid but I'm having SQL query issues.
I have a table with lots of lines of transactions which all refer to different stores, for example:
Store..............._Sales_............._Month_
Reading............200k..............April
Leeds...............50k................April
Manchester........70k................May
Reading............100k..............May
I need to come up with the average Sales for the combined months as a total. I.e. the average Store revenue for a given period is 200k+ 50k + 70k +100k / *3* (As there are only 3 unique stores) - hopefully this makes sense!
So essentially I am trying to do both a SUM query (and grouping by store) and then outputting the average of all stores together. Is this possible?
Thank you,Hello,
This query returns 140 what seems to be the correct value:
with data as
( select 'Reading' Store
, 200 sales
from dual
union
select 'Leeds'
, 50
from dual
union
select 'Manchester'
, 70
from dual
union
select 'Reading'
, 100
from dual
select sum(sales)
, count( distinct store )
, sum(sales)/count(distinct store)
from dataThere are multiple options:
1. You can get two IR's on one page (by using IFRAMEs - search for that word on the Forum)....
2. You create another region with the query above and position that just below the report
3. In the Region Footer call a PL/SQL process (using AJAX) that calculates the value using the query and prints it there (using htp.p)
Greetings,
Roel
http://roelhartman.blogspot.com/
http://www.bloggingaboutoracle.org/
http://www.logica.com/
You can award this reply to your question by marking it as either Helpful or Correct ;-) -
SQL Query clauses and conditions
Hi,
I wanna to get the entire conditions specified in the SQL query to do a specific treatement on them.
in fact, i want to do a syntaxical analyse on the query.
If there is a specific table where query in stored is seperate clauses, objects invoked, conditions used,..., please let me know.
elsewhere, il you have a PL/SQL program that do that, it'll be wonderfull.
Best regards;thank for your reply, but what i need is not the query text, but the seperated query clauses and conditions.
best regards -
How to get sql query data and write into csv file?
I am writing to seek help, in how can I create bat. script which can execute the following logic:
connection to the database
run sql query
create CSV file
output query data, into CSV file
save the CSV file
osql
-S 84.18.111.111
-U adw
-P rem
-i "c:\query.sql"
send ""
sed -e 's/,\s\+/,/g' MCI_04Dec2014.csv > localNoSpaces.csv
-o "c:\MCI_04Dec2014.csv"
This what i have so far, and I am little struggling with the logic after creating CSV file. I am unable to get the above script to work, please advice further, where I may be going wrong.
Can you create if statement logic within window's script, to check for null parameters or data feeds?
Any hints would be most appreciated.Thank you for your reply.
Apology for posting the code irrelevant to the forum, as I am still novice scripting user.
My goal is to create window's script which can compute the above logic and send the final output file (csv), to FTP folder.
Can this logic be implemented via bat. script, if so, is there a example or tutorial i could follow, in order to achieve my task.
Any help would be much appreciated. -
SQL query automation and output to text file
The bcp utility should handle this task pretty easily for you. The documentation is available here.
I know enough SQL to get me by with the few things I currently do in it (but would always like to know and do more). Anyway, I was just recently asked if I could come up with a way to automate the execution of a SQL query we currently manually run, and then have the results of that query output (instead of to the screen in SSMS) to a text file with the ".dat" extension. I've never automated a SQL query before nor have I had the results output to a file. Can anyone give me some pointers on how to tackle this?
The query currently calls to a stored procedure (which does all the work) and just executes it with some given dates from the query so I'm thinking the output will need to come from the stored procedure (and the code for output to a file added there?)
This topic first appeared in the Spiceworks Community -
Hi,
I am trying to get a recordset that samples multiple columns of my Access database for filtering, rather than just one. I looked at a few .asp websites and they say the query would be written like this:
SELECT SystemName, SystemCategory, Branch, Manufacturer
FROM UnmmannedAircraftSystems
WHERE Branch LIKE %MMColParam%
AND PerfSensorPayloads LIKE %MMColParam2%
ORDER BY SystemName ASC
but it never works. The page fails on the server. And I know this type of query works through straight .asp coding, but somehow the way Dreamweaver sets up the variables is killing it.
Anybody have an ideas?
MW<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../../Connections/BleahBleahBleahhhhh" -->
<%
Dim RSfilterRec__MMColParam
RSfilterRec__MMColParam = "1"
If (Request.Form("BranchesUsedby") <> "") Then
RSfilterRec__MMColParam = Request.Form("BranchesUsedby")
End If
%>
<%
Dim RSfilterRec__MMColParam2
RSfilterRec__MMColParam2 = "1"
If (Request.Form("SensorPay") <> "") Then
RSfilterRec__MMColParam2 = Request.Form("SensorPay")
End If
%>
<%
Dim RSfilterRec
Dim RSfilterRec_cmd
Dim RSfilterRec_numRows
Set RSfilterRec_cmd = Server.CreateObject ("ADODB.Command")
RSfilterRec_cmd.ActiveConnection = MM_ConnUASdata_STRING
RSfilterRec_cmd.CommandText = "SELECT SystemName, SystemCategory, Branch, Manufacturer FROM UnmannedAircraftSystems WHERE Branch LIKE ? AND PerfSensorsPayloads LIKE ? ORDER BY SystemName ASC"
RSfilterRec_cmd.Prepared = true
RSfilterRec_cmd.Parameters.Append RSfilterRec_cmd.CreateParameter("param1", 200, 1, 255, "%" + RSfilterRec__MMColParam + "%") ' adVarChar
RSfilterRec_cmd.Parameters.Append RSfilterRec_cmd.CreateParameter("param2", 200, 1, 255, "%" + RSfilterRec__MMColParam2 + "%") ' adVarChar
Set RSfilterRec = RSfilterRec_cmd.Execute
RSfilterRec_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = 10
Repeat1__index = 0
RSfilterRec_numRows = RSfilterRec_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
<style type="text/css">
<!--
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #666666;
margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
color: #000000;
/* Tips for Elastic layouts
1. Since the elastic layouts overall sizing is based on the user's default fonts size, they are more unpredictable. Used correctly, they are also more accessible for those that need larger fonts size since the line length remains proportionate.
2. Sizing of divs in this layout are based on the 100% font size in the body element. If you decrease the text size overall by using a font-size: 80% on the body element or the #container, remember that the entire layout will downsize proportionately. You may want to increase the widths of the various divs to compensate for this.
3. If font sizing is changed in differing amounts on each div instead of on the overall design (ie: #sidebar1 is given a 70% font size and #mainContent is given an 85% font size), this will proportionately change each of the divs overall size. You may want to adjust based on your final font sizing.
.thrColEls #container {
width: 46em; /* this width will create a container that will fit in an 800px browser window if text is left at browser default font sizes */
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
border: 1px solid #000000;
text-align: left; /* this overrides the text-align: center on the body element. */
/* Tips for sidebar1:
1. Be aware that if you set a font-size value on this div, the overall width of the div will be adjusted accordingly.
2. Since we are working in ems, it's best not to use padding on the sidebar itself. It will be added to the width for standards compliant browsers creating an unknown actual width.
3. Space between the side of the div and the elements within it can be created by placing a left and right margin on those elements as seen in the ".thrColEls #sidebar1 p" rule.
.thrColEls #sidebar1 {
float: left;
width: 11em; /* since this element is floated, a width must be given */
background: #EBEBEB; /* top and bottom padding create visual space within this div */
height: 1200px;
padding-top: 15px;
padding-right: 0;
padding-bottom: 15px;
padding-left: 0;
.thrColEls #sidebar2 {
float: right;
width: 11em; /* since this element is floated, a width must be given */
background: #EBEBEB; /* the background color will be displayed for the length of the content in the column, but no further */
padding: 15px 0; /* top and bottom padding create visual space within this div */
height: 1200px;
.thrColEls #sidebar1 h3, .thrColEls #sidebar1 p, .thrColEls #sidebar2 p, .thrColEls #sidebar2 h3 {
margin-left: 10px; /* the left and right margin should be given to every element that will be placed in the side columns */
margin-right: 10px;
height: 100%;
/* Tips for mainContent:
1. If you give this #mainContent div a font-size value different than the #sidebar1 div, the margins of the #mainContent div will be based on its font-size and the width of the #sidebar1 div will be based on its font-size. You may wish to adjust the values of these divs.
2. The space between the mainContent and sidebar1 is created with the left margin on the mainContent div. No matter how much content the sidebar1 div contains, the column space will remain. You can remove this left margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends.
3. To avoid float drop, you may need to test to determine the approximate maximum image/element size since this layout is based on the user's font sizing combined with the values you set. However, if the user has their browser font size set lower than normal, less space will be available in the #mainContent div than you may see on testing.
4. In the Internet Explorer Conditional Comment below, the zoom property is used to give the mainContent "hasLayout." This avoids several IE-specific bugs that may occur.
.thrColEls #mainContent {
margin: 0 12em 0 12em; /* the right margin can be given in ems or pixels. It creates the space down the right side of the page. */
/* Miscellaneous classes for reuse */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
float: right;
margin-left: 8px;
.fltlft { /* this class can be used to float an element left in your page */
float: left;
margin-right: 8px;
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
-->
</style><!--[if IE]>
<style type="text/css">
/* place css fixes for all versions of IE in this conditional comment */
.thrColEls #sidebar1, .thrColEls #sidebar2 { padding-top: 30px; }
.thrColEls #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]--></head>
<body class="thrColEls">
<div id="container">
<div id="sidebar1">
<h3> </h3>
<!-- end #sidebar1 --></div>
<div id="sidebar2">
<h3> </h3>
<!-- end #sidebar2 --></div>
<div id="mainContent">
<h1>
<table border="1">
<tr>
<td>ID</td>
<td>SystemName</td>
<td>SystemCategory</td>
<td>Branch</td>
<td>Manufacturer</td>
<td>Status</td>
<td>Inventory</td>
<td>PlatformCost</td>
<td>SystemCost</td>
<td>PlannedBuyToDate</td>
<td>PlannedBuyYear1</td>
<td>PlannedBuyYear1Quantity</td>
<td>PlannedBuyYear2</td>
<td>PlannedBuyYear2Quantity</td>
<td>PlannedBuyYear3</td>
<td>PlannedBuyYear3Quantity</td>
<td>PlannedBuyYear4</td>
<td>PlannedBuyYear4Quantity</td>
<td>PlannedBuyYear5</td>
<td>PlannedBuyYear5Quantity</td>
<td>PlannedBuyYear6</td>
<td>PlannedBuyYear6Quantity</td>
<td>PlannedBuyYear7</td>
<td>PlannedBuyYear7Quantity</td>
<td>PlannedBuyYear8</td>
<td>PlannedBuyYear8Quantity</td>
<td>PlaformOperationPicLink</td>
<td>OrthoDrawingLink</td>
<td>Capability</td>
<td>BackgroundSysDescrip</td>
<td>SystemDescription</td>
<td>CharLength</td>
<td>CharWingSpan</td>
<td>CharGrossWgt</td>
<td>CharPayloadWgt</td>
<td>CharEngines</td>
<td>CharFuelWgtType</td>
<td>DataLinks1</td>
<td>DataLinks2</td>
<td>DataLinks3</td>
<td>Frequencies1</td>
<td>Frequencies2</td>
<td>Frequencies3</td>
<td>PerfEndurance</td>
<td>PerfRadius</td>
<td>PerfCeiling</td>
<td>PerfAirspeeds</td>
<td>PerfTakeoff</td>
<td>PerfLanding</td>
<td>PerfSensorsPayloads</td>
<td>PerfSensorModels</td>
<td>PayloadCharInternalSize</td>
<td>PayloadCharInternalWgt</td>
<td>PayloadCharInternalPwr</td>
<td>PayloadCharInternalEnv</td>
<td>PayloadCharExternalSize</td>
<td>PayloadCharExternalWgt</td>
<td>PayloadCharExternalPwr</td>
<td>PayloadCharExternalEnv</td>
</tr>
<% While ((Repeat1__numRows <> 0) AND (NOT RSfilterRec.EOF)) %>
<tr>
<td><%=(RSfilterRec.Fields.Item("ID").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("SystemName").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("SystemCategory").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("Branch").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("Manufacturer").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("Status").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("Inventory").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlatformCost").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("SystemCost").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyToDate").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear1").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear1Quantity").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear2").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear2Quantity").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear3").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear3Quantity").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear4").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear4Quantity").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear5").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear5Quantity").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear6").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear6Quantity").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear7").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear7Quantity").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear8").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlannedBuyYear8Quantity").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PlaformOperationPicLink").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("OrthoDrawingLink").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("Capability").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("BackgroundSysDescrip").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("SystemDescription").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("CharLength").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("CharWingSpan").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("CharGrossWgt").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("CharPayloadWgt").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("CharEngines").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("CharFuelWgtType").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("DataLinks1").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("DataLinks2").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("DataLinks3").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("Frequencies1").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("Frequencies2").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("Frequencies3").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PerfEndurance").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PerfRadius").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PerfCeiling").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PerfAirspeeds").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PerfTakeoff").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PerfLanding").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PerfSensorsPayloads").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PerfSensorModels").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PayloadCharInternalSize").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PayloadCharInternalWgt").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PayloadCharInternalPwr").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PayloadCharInternalEnv").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PayloadCharExternalSize").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PayloadCharExternalWgt").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PayloadCharExternalPwr").Value)%></td>
<td><%=(RSfilterRec.Fields.Item("PayloadCharExternalEnv").Value)%></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
RSfilterRec.MoveNext()
Wend
%>
</table>
</h1>
<!-- end #mainContent --></div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
<!-- end #container --></div>
</body>
</html>
<%
RSfilterRec.Close()
Set RSfilterRec = Nothing
%> -
SQL query editor and "like" with a parameter (can't get it to work).
I've been following all sorts of directions on how to use mysql a table and modifying the query to accept a parameter, funny thing is no matter how I try to construct the simplest query, the query editor does not parse the query properly when using the "LIKE" statement.
Using 3.11 and/or 3.12 of the J/connector with no success.
I am using a query that resembles the following:
select all table.fieldname, table.fieldname2 from tablename where table.fieldname like '%?%'
It parses correctly but the code when run can not find the parameter as it reports the number of paramenters as being incorrect.
I have tried these varriations of the "like" statement.
'%?%' - expected this to work, it parses correctly but errors out claiming invalid number of parameters.
%?% - without quotes causes parsing errors.
'?' - parses correctly but isn't the correct query.
? - again without quotes causes parsing errors,even if it did it isn't the correct query.
If I set the query to use a value instead of a parameter - it works fine.
Hints? Suggestions? Bug?
Thanks in advance.Hmm, try use
select ... like ?
And path this kind of string as the parameter to your query
String findCriteria = "what you are looking for";
String parameter = "'%" + findCriteria + "%'";Roman. -
Executing the sam SQL Query again and again on the same records?
Hi currently we have a system that will compute certain charge information base on a file finance department send to us from another system
The problem is that their file contains of Account with bank records and account with no bank records.
for thos account with bank records it will just send to us and we will just update it..and those account will be updated...
but for those account that have no bank records ..it will send to us again and again..and these no bank records account will accumulate
the finance department mention that there is not much they can do on their side except sending us the file
is there any gd solution for this people kind to share?Well one simple solution which i can think of is to persist Non-bank accounts in a Serializable Object and save it in a temporary cache.
Now before running a query on them and then trying to update the database checkout the peristed cache, check whether data records exist their or not
if they do, dont update that records in the database.
or define your database tables in such a way that there is an indication of abt bank & non-bak records and write a query / procedure in such a way that it do not update the duplicate non-bank records.
Hope this might help :)
REGARDS,
RaHuL -
Sql query obitype and sys acct
Does B1 assign "obitype" and "sys account" _sysxxxxxxxxxx automatically? What does each mean and feature?
Dear Lily,
The objtype is an id representation of each document type used in SBO.
Eg.
13 - AR Invoice related document
203 - AR Downpayment Invoice
14 - AR Credit Memo
18 - AP Invoice related document
and so on... you should be able to find a document called "How to Interpret Transaction Type Abbrieviations" from the SAP portal documentation page.
The account code SYS_0000XXXXXX you find the in the JDT table is also a representation id for the various accounts in your Chart of Accounts. This format of account id is used, ecause the Chart of Accounts used in your company database is of type 'Account Segmentation'. To find the relevant Account Code (as defined in your Chart of Accounts) for this segementation id SYS_0000XXXXXX, link this value to the 'Code' column of the OACT table.
Hope it helps.
Warmest Regards,
Chinho -
Can we change/Modify BI server generated Sql query and run to fetch data
Hi,
My client is saying that there is an option to modify bi server generated sql query to fetch data from source.
question:As a request is made in presentation services, A dynamic sql query is generated and fetches data from source. all this is loggedin Nqlquery log..well can we change/modify the sql query generated and run modified sql query to fetch data from source. ., if so how? if not why?
Thanks in advance
Edited by: user10794468 on Jun 16, 2009 6:29 PM
Edited by: user10794468 on Aug 12, 2009 6:58 PMThank you so much for your reply..
..Can we also modify sql query generated by bi server to fetech data. the query's which we see in query log file.. -
Certain queries built using Crystal Reports do not return a full result set of data as expected, compared to using standard SQL wildcards in an interactive native SQL tool.
Does anybody know if any of these are bugs in Crystal Reports?
See example data and queries with their associated results below.
Example:
Table name: customer
Column definitions:
lname char(20)
state char(2)
Relevant rows from our demo database, queried from the native interactive SQL tool are shown below. For the purposes of illustration, I modified some of the state fields so that there were examples of 'N ', ' N' and 'N' (space in front of the letter N, space after the letter N, and just the letter N with no spaces). I have also added the single quote characters in the query results for those rows to highlight where the spaces exist or do not exist in the data:
1 > select id,lname,city,state from customer
where state like '%N%' or lname like '%en %'
Col. id lname city state
[ 1] 101 Devlin Rutherford 'N ' < was NJ
[ 2] 102 Reiser New York 'N' < was NY
[ 3] 104 Mason Knoxville NN
[ 4] 105 McCarthy Carmel IN
[ 5] 107 Colburn Raleigh NC
[ 6] 108 Goforth Chattanooga ' N' < was TN
[ 7] 111 Ricci Syracuse NY
[ 8] 112 McDonough Brooklyn Park MN
[ 9] 113 Kaiser Minneapolis MN
[ 10] 114 Chopp St Paul MN
[ 11] 115 Phillips St Paul MN
[ 12] 116 Gugliuzza Mamaroneck NY
[ 13] 118 Sanford Raleigh NC
[ 14] 120 Stein Elmsford NY
[ 15] 121 Elkins Carmel IN
[ 16] 129 Fahrvergnugen Baltimore MD
[ 17] 131 Sinnot Bohemia NY
[ 18] 132 King Fort Wayne IN
[ 19] 135 Clarke New York NY
[ 20] 136 Wooten Plymouth MN
[ 21] 137 Morfek Ft. Wayne IN
[ 22] 138 Patoff Burlington ON
[ 23] 141 Pyper Fort Wayne IN
[ 24] 147 Lela Wood Bridge NJ
[ 25] 150 Mason Don Mills ON
[ 26] 152 Jones Austin NY
[ 27] 160 Nette Port Washington NY
[ 28] 163 Peese Mississauga ON
[ 29] 165 Mournen Ft. Wayne IN
[ 30] 169 Terlemezian Matthews NC
[ 31] 177 Zubenko Raleigh NC
[ 32] 179 Nguyen Miramar FL
[ 33] 180 Peros Rochester NY
[ 34] 181 Teeven Washington DC
[ 35] 198 Chen San Ramon CA
[ 36] 199 Mentary Rochester NY
[ 37] 202 Murphy White Plains NY
[ 38] 208 Suess Albany NY
[ 39] 221 Johnson Santa Fe NM
[ 40] 331 Johansen New Orleans LA
[ 41] 550 Antolini Fargo ND
[ 42] 552 OToole Nashville TN
[ 43] 665 Thompson Manchester NY
43 rows Affected.
Several queries perform as expected between Crystal Reports and the native SQL query tool. However, in some cases, the results are different. Crystal Reports does not return as much data as the native SQL query tool. I'm not implying which one is correct, I'm merely stating that there is a difference between them.
In the cases below, the 'Crystal Reports record selection formula' is obtained by navigating the Crystal Reports menu: Report -> Selection Formulas -> Record...
Single quotes are not specified in the results below - refer above for the actual data in those rows.
The following cases are inconsistent between the native SQL query tool and Crystal Reports designer:
Case 1:
Length of field to be searched: Short (2 chars)
Wildcard description: letter 'N' + any single character
Native interactive SQL query and results:
1 > select id,lname,city,state from customer where state like 'N_'
Columns: id lname city state
[ 1] 101 Devlin Rutherford N
[ 2] 102 Reiser New York N
[ 3] 104 Mason Knoxville NN
[ 4] 107 Colburn Raleigh NC
[ 5] 111 Ricci Syracuse NY
[ 6] 116 Gugliuzza Mamaroneck NY
[ 7] 118 Sanford Raleigh NC
[ 8] 120 Stein Elmsford NY
[ 9] 131 Sinnot Bohemia NY
[ 10] 135 Clarke New York NY
[ 11] 147 Lela Wood Bridge NJ
[ 12] 152 Jones Austin NY
[ 13] 160 Nette Port Washington NY
[ 14] 169 Terlemezian Matthews NC
[ 15] 177 Zubenko Raleigh NC
[ 16] 180 Peros Rochester NY
[ 17] 199 Mentary Rochester NY
[ 18] 202 Murphy White Plains NY
[ 19] 208 Suess Albany NY
[ 20] 221 Johnson Santa Fe NM
[ 21] 550 Antolini Fargo ND
[ 22] 665 Thompson Manchester NY
22 rows Affected.
Crystal Reports record selection formula and results:
{customer.state} like "N?"
id lname city state
104 Mason Knoxville NN
107 Colburn Raleigh NC
111 Ricci Syracuse NY
116 Gugliuzza Mamaroneck NY
118 Sanford Raleigh NC
120 Stein Elmsford NY
131 Sinnot Bohemia NY
135 Clarke New York NY
147 Lela Wood Bridge NJ
152 Jones Austin NY
160 Nette Port Washington NY
169 Terlemezian Matthews NC
177 Zubenko Raleigh NC
180 Peros Rochester NY
199 Mentary Rochester NY
202 Murphy White Plains NY
208 Suess Albany NY
221 Johnson Santa Fe NM
550 Antolini Fargo ND
665 Thompson Manchester NY
Note that the first two rows are not present here.
Case 2:
Length of field to be searched: Short (2 chars)
Wildcard description: letter 'N' + one space
Native interactive SQL query and results:
1 > select id,lname,city,state from customer where state like 'N '
Columns: id lname city state
[ 1] 101 Devlin Rutherford N
[ 2] 102 Reiser New York N
2 rows Affected.
Crystal Reports record selection formula (menu: Report -> Selection Formulas -> Record...) and results:
{customer.state} like "N "
id lname city state
No data is displayed.
Case 3:
Length of field to be searched: Long (20 chars)
Wildcard description: 0 or more + 'en' + space + 0 or more
Native interactive SQL query and results:
1 > select id,lname,city,state from customer where lname like '%en %'
Columns: id lname city state
[ 1] 129 Fahrvergnugen Baltimore MD
[ 2] 136 Wooten Plymouth MN
[ 3] 165 Mournen Ft. Wayne IN
[ 4] 179 Nguyen Miramar FL
[ 5] 181 Teeven Washington DC
[ 6] 198 Chen San Ramon CA
[ 7] 331 Johansen New Orleans LA
7 rows Affected.
Crystal Reports record selection formula (menu: Report -> Selection Formulas -> Record...) and results:
{customer.lname} like "*en *"
id lname city state
No data is displayed.
Case 4:
Length of field to be searched: Long (20 chars)
Wildcard description: 0 or more + 'en' + any 7 chars
Native interactive SQL query and results:
1 > select id,lname,city,state from customer where lname like '%en_______'
Columns: id lname city state
[ 1] 129 Fahrvergnugen Baltimore MD
1 rows Affected.
Crystal Reports record selection formula (menu: Report -> Selection Formulas -> Record...) and results:
{customer.lname} like "*en???????"
id lname city state
No data is displayed.
Case 5:
Length of field to be searched: Long (20 chars)
Wildcard description: 0 or more + 'en' + seven spaces
Native interactive SQL query and results:
1 > select id,lname,city,state from customer where lname like '%en '
Columns: id lname city state
[ 1] 129 Fahrvergnugen Baltimore MD
1 rows Affected.
Crystal Reports record selection formula (menu: Report -> Selection Formulas -> Record...) and results:
{customer.lname} like "*en "
id lname city state
No data is displayed.Clint,
Yes, I think that would probably work fine.
The point here is that I think there is a bug in the way Crystal Reports processes wild card strings and passes the sql to the downstream database. Crystal Reports should translate the wild card strings into the corresponding sql standard syntax, and pass the wild card string to the database, but it does not appear to be doing this.
At this point, I am only interested in notifying the SAP / Business Objects engineering department of this bug, or in posts that point me to a fix to the bug, rather than a work-around.
Thanks . . .
- Jay -
How to configure a sql query of 110 lines in a DB Adapter
Hi all,
I have a sql query which is 110 lines and i need to use "select"operation in DB Adapter.I dont understand where to put the query in DB Adapter.I worked on a sql query which is 3 or 4 lines but this is the first time iam working on a sql Query with 110 lines.
Please help me.Give me sme link or any document that i can refer.
Thanks,
KiranHI,
Please use the option of Custom Sql and paste it there.
it does not matter what operation are you using but the xsd will form accordingly.
If you need to do only via Select operation in the wizard, than select the tables and add pararmeters in the next screen and try to give the logic there.
I feel the best thing to do would be with the Custom Sql query.
And whatever variables you need to pass dyanamically.
Just put an # symbol before to the column name .
The variable will be formed.
Thanks,
Tirumala Dixit. -
SQL Query (pl/sql function body returning Sql query)
Hi All,
I have created a region of "SQL Query (pl/sql function body returning Sql query)" type and it is working fine , but when I am migrating(export /import) this application from development to systest environment ,
It gives error for this region :
Error ERR-1101 Unable to process function body returning query.
OK
ORA-06550: line 1, column 52: PLS-00306: wrong number or types of arguments in call to 'FU_TRADE_REPORT_QUERY' ORA-06550: line 1, column 45: PL/SQL: Statement ignored
Any pointer ...why this is happening.
Thanks
DikshitIf your function is a stored function that is called from within APEX (function body not coded into the app itself), have you made sure that the function has been created and compiles ok prior to installing your apex app.
If there are some dependency issues between other PL/SQL units or database objects that are causing your function not to be compiled, you apex install will fail as you are trying to reference an uncompelled bit of pl/sql.
Let me know how you get on
Regards
Duncan -
Query on Reoprts-pl/sql function body returning sql query
Hi,
I am facing a starnge problem.. and would like to know the reason for it.
The situation is as follows:
I have a report (pl/sql function body returning sql query based). My query is as follows:
declare
l_query1 varchar2(2000);
begin
if (:P102_min_value is not null and :P102_max_value is null) then
l_query1 := 'select decode(:P102_date,'1',date1) Transaction_Date, decode(:P102_first_name,'2',first_name) First_Name from (
select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=:P102_min_value
return (l_query1);
end if;
end;
This returns the error as :
1 error has occurred
Function returning SQL query: Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the generic columns checkbox below the region source to proceed without parsing.
(ORA-06550: line 7, column 20: PLS-00103: Encountered the symbol "1" when expecting one of the following: * & = - + ; < / > at in is mod remainder not rem <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ between || multiset member SUBMULTISET_)
How do i correct this? am i right in thinking that the single quotes indicating a string within a select query is creating the problem? Beacuse if i use an sql query report and use the following query, it is working fine...
select
decode(:P102_date,'1',date1) Transaction_Date,
decode(:P102_first_name,'2',first_name) First_Name
from (
select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=:P102_min_value
But i need to write pl/sql function, so that multiple report can be returned based on different conditions. Please guide me.
Thanks,
SumanaDoes that mean that both in if and else we need to have same columns selected?
if thats the case.. any idea how i can implement it in my code. The situation here is that the columns that need to be selected are dynamic and keep on changing...
if i try to implement like this and run the page, it gives the following error:
Query is:
declare
l_query1 varchar2(4000);
begin
if apex_application.get_current_flow_sgid(:APP_ID) = apex_application.get_sgid then
if (:P102_min_value is not null and :P102_max_value is null) then
l_query1 := 'select decode(' || :P102_date|| ',''1'',date1) Transaction_Date, decode(' || :P102_first_name || ',''2'',first_name) First_Name from (
select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=' || :P102_min_value ||'
elsif (:P102_min_value is null and :P102_max_value is not null) then
l_query1 := 'select decode(' || :P102_date|| ',''1'',date1) Transaction_Date, decode(' || :P102_first_name || ',''2'',first_name) First_Name from (
select * from MORTGAGE_LOAN_LEADS where APPRX_LOAN_AMOUNT >=' || :P102_max_value ||'
else
l_query1 := 'select date1,first_name from MORTGAGE_LOAN_LEADS where rownum = 1';
end if;
else
l_query1 := 'select date1,first_name from MORTGAGE_LOAN_LEADS where rownum = 1';
end if;
return l_query1;
--dbms_output.put_line( l_query1);
end;
The Error is:
failed to parse SQL query:
ORA-00936: missing expression
If i try to run the same in command prompt, it always goes to the else part... (else of outer if) -
SQL query in powershell Errors on IIF
Hello,
I have put together a Powershell script from examples online to run a SQL query. The query came from Access and it seems Powershell has a problem with the syntax.
I'm pretty new to scripting and adding SQL to the equation isn't helping.
Powershell code
$SQLServer = "ServerName"
$SQLDBName = "DataBase"
$SqlQuery = 'MyQuery'
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$DataSet.Tables[0] | ft -AutoSize
SQL Query
SELECT swName AS Server, swRack AS Rack, swEnvironment AS Environment, IIf([dbo.SW_SERVICE_LVL].[swMonday]=1,"Mon") AS [RebootSchedule], dbo.SW_SERVICE_LVL.swMonBeginTime AS [RebootTime], 2 AS Expr
FROM dbo.SW_SERVICE_LVL INNER JOIN dbo.SW_SPECIALTY ON dbo.SW_SERVICE_LVL.swDiscount = dbo.SW_SPECIALTY.swSpecialtyId
WHERE (((IIf([dbo.SW_SERVICE_LVL].[swMonday]=1,"Mon")) Is Not Null) AND ((dbo.SW_SERVICE_LVL.swGrpResp)="IT Group Name") AND ((dbo.SW_SERVICE_LVL.swRootObjectType)="Server"));
Error given is
Exception calling "Fill" with "1" argument(s): "Incorrect syntax near ')'.
Incorrect syntax near 'IIf'."At line:16 char:1
+ $SqlAdapter.Fill($DataSet)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SqlExceptionThis might be considered a new question but now I got the powershell code to return data from the SQL database.
Now I am looking to output the table to a powershell Array then append the LastRebootTime into that Array. As far as I can tell, this requires a ForEach loop on each servername returned from the SQL query. And I'm stuck on getting that working.
Stop thinking like you know what that means.
Where are you getting lastreboottime? Why does it have to be appended. "Reboottime" is one of thefields in or query. You don't need it.
¯\_(ツ)_/¯
That is a bit strongly worded. Here's what I've got and this is still a work in progress. I've said this before, I am not a scripter. Now I am stuck on adding the LastBootUpTime column into the table returned from the SQL query.
$SQLServer = "ServerName"
$SQLDBName = "DataBase"
$SqlQuery = 'MyQuery'
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet) | Out-Null
$arraydata = @($DataSet)
$SqlConnection.Close()
$servers = @($DataSet.Tables[0]) | select -ExpandProperty Server
Try{
foreach ($server in $servers)
$arraydata += @(GWMI -ComputerName $server -Class Win32_OperatingSystem -ErrorAction SilentlyContinue | select @{LABEL="Server";Expression={$_."csname"}}, @{LABEL='LastBootUpTime'
;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}})
}#end try
Catch{
"Can't work with $server"
$DataSet.Tables[0] | ft -AutoSize #Export-Csv -NoTypeInformation -Path c:\sunday.csv
$arraydata
Maybe you are looking for
-
Installing Adobe Photoshop 2.0
My old Adobe Photoshop 2.0 will not install on OSX 10.5.2. It keeps telling me I do not have Administrative privileges, when I am logged in on an administrative account. The installation doc on the Photoshop says to go to System Preferences and selec
-
How to generate blank cells in cross-tab (Matrix) report
Hi All, I am facing issue in populating blank columns in a cross-tab report.Please help me out as it is urgent....... Thanks in advance. regards, sreekanth
-
When i on the phone, it shows itunes icon. I downloaded itunes, it detected the iphone but asking me to restore before i can sync. how do I get to useable mode?
-
I have just installed OS XMavericks and since installation have not been able to select smart groups to send emails to. Any ideas why? Also I suddenly can't italicise or embolden text in an email. Bunnyfw
-
Optimizing for computer viewing
Forgive me if this has been answered elsewhere, but I have searched without success. I am creating a DVD for an artist that is chock full of TIFF files (all of which are 720x480). The DVD looks great on NTSC monitors, and in simulator, but when playe