CAML Query with Javascript value
Hey everyone,
I am building an Sharepoint 2013 app (SharePoint-Hosted) and using a CAML Query to get the current Item.
The Current Item ID is 1 and i stored it in AccountID, but i want that variable inserted in the CAML Query so i get the proper information.
var AccountID = 1
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=ID LookupId="TRUE"/><Value Type="Text">1</Value></Eq></Where></Query></View>');
But instead of putting the '1' value in the CAML Query, i want the variable AccountID in it... but how?
Already tried this, but that didn't work:
camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=ID LookupId="TRUE"/><Value Type="Text">' + AccountID + '</Value></Eq></Where></Query></View>');
Can someone help me with this?
In forward, many thanks!
Right, you have to use single quotes in a string literal inside double quotes. Just making sure it didn't have NO quotes, as your initial post showed.
Is the ID field actually a lookup field? Or is it just the built-in ID field of the list? If it isn't a field of TYPE Lookup, try this:
camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Number'>" + AccountID + "</Value></Eq></Where></Query></View>");
Danny Jessee
MCPD - SharePoint Developer 2010
MCTS - SharePoint 2010, Configuring
dannyjessee.com/blog
Similar Messages
-
CAML Query with 10 AND conditions
Hello,
I need some help with a CAML query. This particular query needs to have 10 AND conditions. Quite frankly, with all the nesting it is driving me a little nuts:
What I have is:
<Query>
<Where>
<And>
<And>
<And>
<And>
<And>
<And>
<And>
<And>
<And>
<Eq><FieldRef Name='Column1' LookupId='TRUE' /><Value Type='Text'>10341</Value></Eq>
<Eq><FieldRef Name='Column2' LookupId='TRUE' /><Value Type='Text'>9539</Value></Eq>
</And>
<Eq><FieldRef Name='Column3' LookupId='TRUE' /><Value Type='Text'>183</Value></Eq>
</And>
<Eq><FieldRef Name='Column4' LookupId='TRUE' /><Value Type='Text'>35</Value></Eq>
</And>
<IsNull><FieldRef Name='Column5' /></IsNull>
</And>
<Eq><FieldRef Name='Column6' LookupId='TRUE' /><Value Type='Text'>4387</Value></Eq>
</And>
<Eq><FieldRef Name='Column7' LookupId='TRUE' /><Value Type='Text'>4204</Value></Eq>
</And>
<Eq><FieldRef Name='Column8' LookupId='TRUE' /><Value Type='Text'>36</Value></Eq>
</And>
<Eq><FieldRef Name='Column9' LookupId='TRUE' /><Value Type='Text'>213</Value></Eq>
</And>
<IsNull><FieldRef Name='Column10' /></IsNull>
</And>
</Where>
</Query>
I have added this into my ItemAdding Event Receiver as it will basically do a check for duplicate items based on the 10 columns.
If anyone can help guide me in this, it would be much appreciated. I have been using a CAML Query Builder to help.http://webcache.googleusercontent.com/search?q=cache:xji7jOxa5_EJ:aasai-sharepoint.blogspot.com/2013/02/caml-query-with-multiple-conditions.html+&cd=3&hl=en&ct=clnk&gl=in
http://stackoverflow.com/questions/6203821/caml-query-with-nested-ands-and-ors-for-multiple-fields
Since you are not allowed to put more than two conditions in one condition group (And | Or) you have to create an extra nested group (MSDN). The expression
A AND B AND C looks like this:
<And>
A
<And>
B
C
</And>
</And>
Your SQL like sample translated to CAML (hopefully with matching XML tags ;) ):
<Where>
<And>
<Or>
<Eq>
<FieldRef Name='FirstName' />
<Value Type='Text'>John</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='LastName' />
<Value Type='Text'>John</Value>
</Eq>
<Eq>
<FieldRef Name='Profile' />
<Value Type='Text'>John</Value>
</Eq>
</Or>
</Or>
<And>
<Or>
<Eq>
<FieldRef Name='FirstName' />
<Value Type='Text'>Doe</Value>
</Eq>
<Or>
<Eq>
<FieldRef Name='LastName' />
<Value Type='Text'>Doe</Value>
</Eq>
<Eq>
<FieldRef Name='Profile' />
<Value Type='Text'>Doe</Value>
</Eq>
</Or>
If this helped you resolve your issue, please mark it Answered -
How could I replace hard coded value in my sql query with constant value?
Hi all,
Could anyone help me how to replace hardcoded value in my sql query with constant value that might be pre defined .
PROCEDURE class_by_day_get_bin_data
in_report_parameter_id IN NUMBER,
in_site_id IN NUMBER,
in_start_date_time IN TIMESTAMP,
in_end_date_time IN TIMESTAMP,
in_report_level_min IN NUMBER,
in_report_level_max IN NUMBER
IS
bin_period_length NUMBER(6,0);
BEGIN
SELECT MAX(period_length)
INTO bin_period_length
FROM bin_data
JOIN site_to_data_source_lane_v
ON bin_data.data_source_id = site_to_data_source_lane_v.data_source_id
JOIN bin_types
ON bin_types.bin_type = bin_data.bin_type
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >= in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time < in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data.bin_type = 2
AND bin_data.period_length <= 60;
--Clear the edr_class_by_day_bin_data temporary table and populate it with the data for the requested
--report.
DELETE FROM edr_class_by_day_bin_data;
SELECT site_to_data_source_lane_v.site_id,
site_to_data_source_lane_v.site_lane_id,
site_to_data_source_lane_v.site_direction_id,
site_to_data_source_lane_v.site_direction_name,
bin_data_set.start_date_time,
bin_data_set.end_date_time,
bin_data_value.bin_id,
bin_data_value.bin_value
FROM bin_data
JOIN bin_data_set
ON bin_data.bin_serial = bin_data_set.bin_serial
JOIN bin_data_value
ON bin_data_set.bin_data_set_serial = bin_data_value.bin_data_set_serial
JOIN site_to_data_source_lane_v
ON bin_data.data_source_id = site_to_data_source_lane_v.data_source_id
AND bin_data_set.lane = site_to_data_source_lane_v.data_source_lane_id
JOIN (
SELECT CAST(report_parameter_value AS NUMBER) lane_id
FROM report_parameters
WHERE report_parameters.report_parameter_id = in_report_parameter_id
AND report_parameters.report_parameter_group = 'LANE'
AND report_parameters.report_parameter_name = 'LANE'
) report_lanes
ON site_to_data_source_lane_v.site_lane_id = report_lanes.lane_id
JOIN (
SELECT CAST(report_parameter_value AS NUMBER) class_id
FROM report_parameters
WHERE report_parameters.report_parameter_id = in_report_parameter_id
AND report_parameters.report_parameter_group = 'CLASS'
AND report_parameters.report_parameter_name = 'CLASS'
) report_classes
ON bin_data_value.bin_id = report_classes.class_id
JOIN edr_rpt_tmp_inclusion_table
ON TRUNC(bin_data_set.start_date_time) = TRUNC(edr_rpt_tmp_inclusion_table.date_time)
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >= in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time < in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data_set.start_date_time >= in_start_date_time
AND bin_data_set.start_date_time < in_end_date_time
AND bin_data.bin_type = 2
AND bin_data.period_length = bin_period_length;
END class_by_day_get_bin_data;In the above code I'm using the hard coded value 2 for bin type
bin_data.bin_type = 2But I dont want any hard coded number or string in the query.
How could I replace it?
I defined conatant value like below inside my package body where the actual procedure comes.But I'm not sure whether I have to declare it inside package body or inside the procedure.
bin_type CONSTANT NUMBER := 2;But it does't look for this value. So I'm not able to get desired value for the report .
Thanks.
Edited by: user10641405 on May 29, 2009 1:38 PMDeclare the constant inside the procedure.
PROCEDURE class_by_day_get_bin_data(in_report_parameter_id IN NUMBER,
in_site_id IN NUMBER,
in_start_date_time IN TIMESTAMP,
in_end_date_time IN TIMESTAMP,
in_report_level_min IN NUMBER,
in_report_level_max IN NUMBER) IS
bin_period_length NUMBER(6, 0);
v_bin_type CONSTANT NUMBER := 2;
BEGIN
SELECT MAX(period_length)
INTO bin_period_length
FROM bin_data
JOIN site_to_data_source_lane_v ON bin_data.data_source_id =
site_to_data_source_lane_v.data_source_id
JOIN bin_types ON bin_types.bin_type = bin_data.bin_type
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >=
in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time <
in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data.bin_type = v_bin_type
AND bin_data.period_length <= 60;
--Clear the edr_class_by_day_bin_data temporary table and populate it with the data for the requested
--report.
DELETE FROM edr_class_by_day_bin_data;
INSERT INTO edr_class_by_day_bin_data
(site_id,
site_lane_id,
site_direction_id,
site_direction_name,
bin_start_date_time,
bin_end_date_time,
bin_id,
bin_value)
SELECT site_to_data_source_lane_v.site_id,
site_to_data_source_lane_v.site_lane_id,
site_to_data_source_lane_v.site_direction_id,
site_to_data_source_lane_v.site_direction_name,
bin_data_set.start_date_time,
bin_data_set.end_date_time,
bin_data_value.bin_id,
bin_data_value.bin_value
FROM bin_data
JOIN bin_data_set ON bin_data.bin_serial = bin_data_set.bin_serial
JOIN bin_data_value ON bin_data_set.bin_data_set_serial =
bin_data_value.bin_data_set_serial
JOIN site_to_data_source_lane_v ON bin_data.data_source_id =
site_to_data_source_lane_v.data_source_id
AND bin_data_set.lane =
site_to_data_source_lane_v.data_source_lane_id
JOIN (SELECT CAST(report_parameter_value AS NUMBER) lane_id
FROM report_parameters
WHERE report_parameters.report_parameter_id =
in_report_parameter_id
AND report_parameters.report_parameter_group = 'LANE'
AND report_parameters.report_parameter_name = 'LANE') report_lanes ON site_to_data_source_lane_v.site_lane_id =
report_lanes.lane_id
JOIN (SELECT CAST(report_parameter_value AS NUMBER) class_id
FROM report_parameters
WHERE report_parameters.report_parameter_id =
in_report_parameter_id
AND report_parameters.report_parameter_group = 'CLASS'
AND report_parameters.report_parameter_name = 'CLASS') report_classes ON bin_data_value.bin_id =
report_classes.class_id
JOIN edr_rpt_tmp_inclusion_table ON TRUNC(bin_data_set.start_date_time) =
TRUNC(edr_rpt_tmp_inclusion_table.date_time)
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >=
in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time <
in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data_set.start_date_time >= in_start_date_time
AND bin_data_set.start_date_time < in_end_date_time
AND bin_data.bin_type = v_bin_type
AND bin_data.period_length = bin_period_length;
END class_by_day_get_bin_data; -
How to force readObejct query with PK value to go to DB?
The default behaviour for read-object queries with a PK value is to use the cache and not go to the database. How can we change this behaviour?
We have cases that a row was deleted by some other process not through toplink, but the corresponding object still in the cache and if you use the readObject query with PK value, the object will be returned as result.
Thanks in advance,There are several mechanisms to disable caching in TopLink. Note that disabling caching will affect your performance.
In 9.0.4 you can use:
- You can configure you cache type to use a WeakIdentityMap to ensure that only referenced objects are cached.
- On descriptor you can call disableCacheHits() and alwaysRefreshCache() in code or click these options on the Caching/Identity tab in the Mapping Workbench.
- Or to explicitly remove a deleted object from the cache uses session.removeFromIdentityMap(), but you must ensure there are no other objects referencing it.
In 10.1.3 you can also use:
- On descriptor you can call setIsIsolated(true) in code, or select isolated in the Caching tab in the Mapping Workbench.
- Alternatively you can set a CacheInvalidationPolicy on your descriptor to ensure objects are not cached for longer than a specified time, or invalidated daily.
- Or to explicitly invalidate a deleted object use, session.getIdentityMapAccessor().invalidateObject() -
Problem with caml query in javascript
hi friends
i am using caml query to retrieve single list item
ReviewQuery.set_viewXml('<view><query><Where><Eq><FieldRef Name=\'PNet_x002d_No\' /><Value Type=\'Text\'>'+id123+'</Value></Eq></Where></query></view>');
my problem is if quried id is available in list it is showing properly. but if queried item is not there then it is showing other item in it.Hi,
I suggest you debug the code and check if the variable value is valid.
Here is a code snippet for your reference :
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("callCSOM");
function callCSOM()
$("#Button1").click(function()
// Make sure the SharePoint script file 'sp.js' is loaded before your code runs.
ExecuteOrDelayUntilScriptLoaded(sharePointReady, "sp.js");
function sharePointReady()
getListItems();
var clientContext;
var currentUser;
var targetWeb;
var message = "Web retrieved:";
function getListItems()
// Create an instance of the current context to return context information
clientContext = SP.ClientContext.get_current();
//Returns the list with the specified title from the collection
var oList = clientContext.get_web().get_lists().getByTitle('list');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(‘<ViewFields><FieldRef Name='Title' /></ViewFields><Where> <Eq><FieldRef Name='Title' /><Value Type='Text'>12</Value></Eq> </Where>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
function onRequestSucceeded()
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext())
//Gets the current element in the collection
var oListItem = listItemEnumerator.get_current();
message += '___'+'Title: ' + oListItem.get_item('Title');
message += '___'+'ID: ' + oListItem.get_item('ID');
message += '________________________________________________';
$("#div1").text(message);
//the delegate of the method that is called when the request is executed unsuccessfully
function onRequestFailed(sender, args)
alert('Error: ' + args.get_message());
</script>
<input id="Button1" type="button" value="Run Code"/>
<p/>
<div id="div1">test</div>
Also, you can build CAML Query in the CAML Designer:
http://www.camldesigner.com/
Feel free to reply if the issue still exists.
Best regards
Patrick Liang
TechNet Community Support -
URL data type in CAML Query with Client side object model
hi,
How do I write a CAML query to filter list items based on the URL field using it's Description?
Same with REST API. How do I construct a REST query so that filter list items based on the URL data type using it's Description.Hi Cooltechie,
Thanks for posting your query, Below are the example that you can use in your CAML query
<Where><Eq><FieldRef Name="FileRef"/><Value Type="Url">sites/SiteCollection/SubSite/Site Documents/Excel Report.xls</Value></Eq></Where>
Note: Do not include the server name or beginning /.
The following examples assuming you have a list or library setup with a URL column named "My Document".
The link is to a document that is hosted on the sharepoint server (do not need server name):
<Where><Eq><FieldRef Name="My_x0020_Document"/><Value Type="URL">/sites/subsite/Site%20Documents/Excel%20Report.xls</Value></Eq></Where>
The link is an absolute URL to something not on the server... for example http://www.google.com:
<Where><Eq><FieldRef Name="My_x0020_Document"/><Value Type="URL">http://www.google.com</Value></Eq></Where>
I hope this is helpful to you, mark it as Helpful.
If this works, Please mark it as Answered.
Regards,
Dharmendra Singh (MCPD-EA | MCTS)
Blog : http://sharepoint-community.net/profile/DharmendraSingh -
Infoset query with cero values
Hi
I have an infoset query that reads the information from an infoset. The infoset query is able to read the values, because it shows me values, but everything is cero, although I have values different from 0.
But if it didn`t find values it would tell me a different message as "No application data found" or something like this.
Then the problem is, my infoset read values, but everything that shows me is cero, and that´s not true.
Thanks and regards
SEM SEMHi,
What do you mean with the join condition ?
I have an infoset query with only one ODS inside. I didn´t want to build a query directly to the ODS as I did´t want to mark the flag available for reporting in the ODS, as it already had very importat data and I didn´t want to damage the ODS data. That´s why I have built and infoset query with one ODS inside, and in this case I don´t understand the join condition....
Regards
SEM SEM
Does anybody know something ????
Regards
SEM SEM
Message was edited by:
SEM SEM -
Question about caml query with UserID/ parameter (working outside of sharepoint )
I have to develop a custom view. I should take the current user and query it in List1 to obtain owned group names. Then I am supposed to query each group name in a List2 to obtain corresponding users. And In a new custom list view I should display those users..
Let's assume I'm working in a c# class in VS. Below is my initial code to fetche owned groups by the current user.
SPQuery query = new SPQuery();
query.ViewFields = @"<FieldRef Name='Title'/>";
query.Query = @"<Where><Eq><FieldRef Name='Title' /><Value Type='Integer'><UserID/></Value></Eq></Where>";
SPList lstUsers = web.Lists["Users"];
SPListItemCollection userItems = lstUsers.GetItems(query);
foreach (SPListItem myitem in userItems)
{Response.Write(myitem["Title"].ToString());}
The "<UserID/>" parameter in caml query does not work outside...
query.Query = @"<Where><Eq><FieldRef Name='Title' /><Value Type='Integer'><UserID/></Value></Eq></Where>";
How can I obtained the current logged user from outside of sharepoint?
Should I write my code somewhere other then a seperate vs c# class?
I appreciate any idea and suggestions....If you are quering a User ID of UserField, you need to add LookupId='True'/ to FieldRef
<Eq>
<FieldRef Name=Owner' LookupId='True'/>
<Value Type='User' >2</Value>
</Eq>
Thanks, Rocky Fernandes -
CAML Query with ECMA script, ORDERBY not working
Hi, I'm trying to get this CAML query to order by created date. Seems like no matter what I do, it shows me the oldest items first. Here's my code:
function retrieveListItemsInclude() {
var clientContext = new SP.ClientContext();
var oList = clientContext.get_web().get_lists().getByTitle('NewsItems');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Neq><FieldRef Name=\'Deleted\' /><Value Type=\'Integer\'>1</Value></Neq></Where><OrderBy><FieldRef Name=\'Created\' Ascending=\'FALSE\'/></OrderBy></Query><RowLimit>10</RowLimit><ViewFields><FieldRef
Name=\'Title\'/><FieldRef Name=\'Link\'/><FieldRef Name=\'Description\'/><FieldRef Name=\'PubDate\'/><FieldRef Name=\'Source\'/><FieldRef Name=\'Topics\'/><FieldRef Name=\'ImageTag\'/><FieldRef Name=\'ImageSource\'/><FieldRef
Name=\'Created\'/></ViewFields></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem, 'Include(Title, Link, Description, PubDate, Source, Topics, ImageTag, ImageSource, Created)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
I tried ordering my ID, Created or Created_x0020_Date, and none of it changes the output at all.
As a related question, how do I debug this CAML query? Are there any tools?Hi,
Please change the CAML query as below:
<where><neq><fieldref name=\'Deleted\' /><value type=\'Number\'>1</value></neq></where>
The following code for your reference:
string siteURL = "http://siteURL/";
string listName = "CustomList";
ClientContext context = new ClientContext(siteURL);
//specific user
NetworkCredential credentials = new NetworkCredential("username", "password", "domain");
context.Credentials = credentials;
List oList = context.Web.Lists.GetByTitle(listName);
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<view><query><where><neq><fieldref name=\'Deleted\' /><value type=\'Number\'>1</value></neq></where><orderby><fieldref name=\'Created\' ascending=\'False\' /></orderby></query><rowlimit>10</rowlimit></view>";
ListItemCollection collListItem = oList.GetItems(camlQuery);
context.Load(collListItem);
context.ExecuteQuery();
foreach (ListItem oListItem in collListItem)
Console.WriteLine("ID: {0}", oListItem.Id);
If the issue still exists, please check the "Deleted" field type.
Here is a CAML query tool for your reference.
http://spcamlqueryhelper.codeplex.com/
Thanks,
Dennis Guo
TechNet Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Dennis Guo
TechNet Community Support -
Fetching file size using CAML query in Javascript client object model
Hi,
I am using the Javascript client object model to retrieve contents of a document library.
I have a document library, which contains a folder "Folder1" . "Folder1" has a zip file. I would like to get the file size of the zip file.
I have tried the below code, but not sure, how to fetch the file size.
function FetchImage() {
var clientcontext = new SP.ClientContext.get_current();
var oweb = clientcontext.get_web();
var olibrary = oweb.get_lists().getByTitle(DocLibrary);
var query = new SP.CamlQuery();
query.set_folderServerRelativeUrl("Lists/DocLibrary/folder1/");
folder = olibrary.getItems(query);
clientcontext.load(folder, 'Include(Title,ContentType, FileLeafRef,FileDirRef,File)');
clientcontext.executeQueryAsync(Function.createDelegate(this, this.RenderDataOnSuccess), Function.createDelegate(this, this.RenderDataOnFailure));
function RenderDataOnSuccess() {
var ListEnumerator = this.folder.getEnumerator();
while (ListEnumerator.moveNext()) {
var currentItem = ListEnumerator.get_current();
if (_contentType.get_name() != "Folder") {
var File = currentItem.get_file();
if (File != null) {
// Fetch file size
How to fetch the file size?
Thanks<script>
function getSize()
var myFSO = new ActiveXObject("Scripting.FileSystemObject");
var filepath = document.upload.file.value;
var thefile = myFSO.getFile(filepath);
var size = thefile.size;
alert(size + " bytes");
</script>
http://social.msdn.microsoft.com/Forums/en-US/e5d2ff3d-01c7-4cc0-a081-29a4dfbb0fad/getting-the-sharepoint-list-attachment-size-using-javascript?forum=sharepointcustomizationlegacy -
PHP+MySQL query with empty value
Hi!
Software is DW8 with Apache 2.0.48, MySQL ver. 4.0.15a, PHP
4.2.3.
We had problem when a submitted value for 'regionID' in the
submit page
was left blank and the following error message appears in the
result page:
"You have an error in your SQL syntax. Check the manual that
corresponds
to your MySQL server version for the right syntax to use near
'LIMIT 0,
3' at line 1"
The problem was solved by adding at the top of the page:
<?php
if (isset($_POST['regionID']) &&
empty($_POST['regionID'])) {
$_POST['regionID'] = '0';
?>
How to change the above code to retrieve ALL records when an
empty \
blank value is submitted for 'regionID'?
TIA
Nanubbgirl wrote:
> Something I picked up at a PHP/MySQL seminar...
$_REQUEST works in place of
> either $_GET or $_POST. It basically means use either
get or post. But it is
> less precise because it can pick up either variable and
has to think about the
> request...
I'm afraid you've picked up rather poor information.
$_REQUEST relies on
register_globals being turned on. Since register_globals is
considered a
major security risk, the default setting has been off since
April 2002.
Many hosting companies have turned register_globals on, in
spite of the
security problems, because so many poorly written scripts
rely on it.
The PHP development team has decided to resolve this security
issue once
and for all by removing register_globals from PHP 6.
Forget $_REQUEST. Use $_POST and $_GET always. It's safer,
and it's
futureproof.
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/ -
Query with scalar valued function with date filter
Hello experts
i have a problem by filtering my results with the date
i have written the following code
SELECT
T1.ItemCode
, T1.Dscription
,DBO.F_CALCULATION_QUANTITY(T1.ITEMCODE)
FROM OINV T0
INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
WHERE
(T0.DOCDATE BETWEEN '2010-11-01' AND '2010-11-30')
and (t2.cardcode ='80022')
and (T0.CANCELED= 'N')
group by t1.itemcode, T1.Dscription, t2.suppcatnum
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER FUNCTION [dbo].[F_CALCULATION_QUANTITY]
(@ITEMCODE AS NVARCHAR(10))
RETURNS
NUMERIC(19,2)
AS
BEGIN
DECLARE
@RESULT1 AS NUMERIC(19,2),
@RESULT2 AS NUMERIC(19,2),
@RESULT AS NUMERIC(19,2)
SELECT @RESULT1=SUM(A.QUANTITY)
FROM INV1 A
JOIN OINV B ON A.DOCENTRY=B.DOCENTRY
WHERE A.ITEMCODE=@ITEMCODE
AND B.DOCDATE BETWEEN '2010-11-01 00:00:00.000' AND '2010-11-30 00:00:00.000'
SELECT @RESULT2=SUM(A.QUANTITY)
FROM RIN1 A
JOIN ORIN B ON A.DOCENTRY=B.DOCENTRY
WHERE A.ITEMCODE=@ITEMCODE
AND B.DOCDATE BETWEEN '2010-11-01 00:00:00.000' AND '2010-11-30 00:00:00.000'
SELECT @RESULT=ISNULL(@RESULT1,0)-ISNULL(@RESULT2,0)
--SELECT @RESULT=@RESULT1- @RESULT2
RETURN @RESULT
END
the problem i have is that i want to filter my results accoring to the date provided by the user. i want it to be dynamic query.
by now, what i do is to edit the docdate in the function in order to get the desired results. this is not what i want.
could you please help me on this way in order to let the user to input the date?if i add the [%] in the query, it does not bring me the right resultsi have already edited the function to
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER FUNCTION [dbo].[F_CALCULATION_QUANTITY]
(@ITEMCODE AS NVARCHAR(10),
@STARTDATE1 as DATETIME,
@ENDDATE1 AS DATETIME
RETURNS
NUMERIC(19,2)
AS
BEGIN
DECLARE
@RESULT1 AS NUMERIC(19,2),
@RESULT2 AS NUMERIC(19,2),
@RESULT AS NUMERIC(19,2)
SELECT @RESULT1=SUM(A.QUANTITY)
FROM INV1 A
JOIN OINV B ON A.DOCENTRY=B.DOCENTRY
WHERE A.ITEMCODE=@ITEMCODE
AND B.DOCDATE BETWEEN (@STARTDATE1) AND (@ENDDATE1)
SELECT @RESULT2=SUM(A.QUANTITY)
FROM RIN1 A
JOIN ORIN B ON A.DOCENTRY=B.DOCENTRY
WHERE A.ITEMCODE=@ITEMCODE
AND B.DOCDATE BETWEEN (@STARTDATE1) AND (@ENDDATE1)
SELECT @RESULT=ISNULL(@RESULT1,0)-ISNULL(@RESULT2,0)
RETURN @RESULT
END
could you please how to edit the query as well?
i have added the following code and it comes up with the right itemcode but the quantity does not work
DECLARE
@ITEMCODE AS NVARCHAR(10),
@STARTDATE1 as DATETIME,
@ENDDATE1 AS DATETIME
SET @STARTDATE1=(SELECT MAX(T0.DOCDATE) FROM oinv t0 WHERE T0.DOCDATE='2010-11-01')
set @ENDDATE1=(SELECT MAX(T0.DOCDATE) FROM oinv t0 WHERE T0.DOCDATE='2010-11-30')
SELECT
T1.ItemCode
, T1.Dscription
,DBO.F_CALCULATION_QUANTITY(@ITEMCODE,@STARTDATE1,@ENDDATE1)
FROM OINV T0
INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
WHERE
(T0.DOCDATE BETWEEN @STARTDATE1 AND @ENDDATE1)
and (t2.cardcode ='80022')
and (T0.CANCELED= 'N')
group by t1.itemcode, T1.Dscription, t2.suppcatnum
the result is this
70200 alert1 0.00
70210 alert2 0.00
70220 alert3 0.00
70230 alert4 0.00
as you can see the quantity is 0 and it shouldnt be
Edited by: Fasolis Vasilios on Oct 31, 2011 10:49 AM -
Select Query with minimum values
Table name: employess_inout
Column name: employee_code number(data type)
IN_Time date(data type)
Out_time date(data type)
i want to select only in_time coloumn data with min intime as in one date A employee have more then 2 times in_time entry
example
employee_code in_time out_time
1 18-mar-12 08:15:21 18-mar-12 13:02:01
1 18-mar-12 14:07:46 18-mar-12 18:01:32
1 19-mar-12 09:15:11 19-mar-12 12:58:54
1 19-mar-12 14:10:01 19-mar-12 16:21:57
1 19-mar-12 16:53:37 19-mar-12 18:15:33
In above example I only want to select in_time column values which is minimum as 18-mar-12(08:15:21) like wise in date 19-mar-12 minimum value is 09:15:11.
Please write the script.
thanks in advanceDear Frank Kulash
the Script is
Select ei.emp_code,p.ename, d.department_name, ds.designation_name,
to_char(ei.intime, 'dd') "IN_Date",
to_char (ei.intime,'hh24:mi') "IN_Time" /*here i used "min" but not solved*/
FROM einout ei, personnel p,departments d, designations ds
where ei.emp_code = '470'
and intime between to_date ('01/03/2012 08:10', 'dd/mm/YYYY hh24:mi')
and to_date ('21/03/2012 10:00','dd/mm/YYYY hh24:mi')
and ei.emp_code = p.emp_code
AND p.dept_code = d.dept_code
and p.desig_code = ds.desig_code
group by ei.emp_code,p.ename, d.department_name, ei.intime,ds.designation_name --, ei.outtime
order by ei.intime, ei.emp_code asc;
Out Put
EMP_CODE ENAME DEPARTMENT_NAME DESIGNATION_NAME IN_Date IN_Time
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 01 09:15
*470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 02 08:58*
*470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 02 14:04*
*470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 02 15:11*
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 03 09:06
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 05 17:07
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 06 09:47
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 07 09:36
*470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 07 19:39* 470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 08 12:16
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 09 09:26
*470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 09 14:08*
I want to take out put
like that
EMP_CODE ENAME DEPARTMENT_NAME DESIGNATION_NAME IN_Date IN_Time
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 01 09:15
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 02 08:58
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 03 09:06
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 05 17:07
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 06 09:47
470 GHULAM YASSEN INFORMATION TECHNOLOGY OFFICER 07 09:36
I only need min time (value) once of A date.
[Bold rows are no need in output]
please tell how it will be possible -
Hi all,
is it possible to create query which check boolean attributes? If yes, how?
Thanks,
MicheleHi Michele,
If you have an attribute (e.g. "Active") of type boolean, then it should be something like:
QueryExp exp = Query.eq(Query.attr("Active"),Query.value(true));Hope this helps,
-- daniel
JMX, SNMP, Java, etc...
http://blogs.sun.com/jmxetc -
Hi, I have this query in my 9ir2 database:
SELECT xmit.u_ii_id, xprol.ii_id
FROM xprol, ( SELECT DISTINCT u_ii_id, ii_id
FROM t
WHERE NVL(key_t,'X') <> 'P') xmit
WHERE xprol.ii_id = xmit.ii_id
AND xmit.u_ii_id <> xprol.ii_id ;
u_ii_id ii_id
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
6220 5765
7898 3409
7898 3409
7898 3409
7898 3409
7898 3409
7898 3409
7898 3409
7898 3409
.The query returns 12.294.938 million of rows.
I need to know de best way to filter this values... maybe using Analytic Functions?
The result of the query must be...
u_ii_id ii_id
6220 5765
7898 3409Thanks!ROW_NUMBER () OVER (PARTITION BY xmit.u_ii_id
ORDER BY xmit.u_ii_id,
xprol.ii_id) AS rn
xprol, (SELECT DISTINCT u_ii_id, ii_id
FROM t
HERE NVL (key_t, 'X') <> 'P') xmit
WHERE xprol.ii_id = xmit.ii_id AND xmit.u_ii_id <>
xprol.ii_id AND rn = 1
/code]this will not work it will give , that needs to be in subquery
ORA-00904: "RN": invalid identifier
below is just an example
SQL> select empno,e.deptno ,row_number() over(partition by deptno order by deptno) rn
2 from emp e, (select deptno from dept1
3 where deptno=10) d
4 where e.deptno=d.deptno
5 and rn=1;
and rn=1
ERROR at line 5:
ORA-00904: "RN": invalid identifier
/pre]
Maybe you are looking for
-
HI Guys, I am in the process of designing the process chains for data loading. I have a situation where I am planning to use local process chains in the meta chain. Situation is like this:I have created Meta Chain for Master Data loading, which is ha
-
Monitor Files installed in system by installer
Hi all, I have one installer of my application built through LabVIEW. I need to monitor the files like *.dll and other files which are installed on the system. Can we get a list of files installed by the installer on the system for monitoring purpos
-
Cannot get on the internet no ip address
My computer stopped connecting to the Internet. Airport says there is no ip address. How can I fix it?
-
the manual says to disconnect everything except the mouse and keyboard, then reboot holding D to enter the hardware diagnostic program. When I follow those directions the computer displays a blank grey screen for a very long time and then boots up no
-
Removing a child instance from a parent child list. - non L2 Caching
I have a parent Entity Parent int id String name @onetomany List <Child> list and a child Entity Child int id String name First, let me say, I have L2 cache turned off. So lets say I have a parent record with three children and I want to remove child