I created two string variables (tot and tot_value) and assigned a value (tot = MyVal) for testing. Then I created an Execute SQL Task which takes (tot) as parameter and the value returned is saved in tot_value.
In the General Tab, i set:
ResultSet to Single row. SQL Source Type to Direct input Query is listed below.
In Parameter Mapping I selected my tot variable with Input DirectionSQL_VARCHAR Data Type 1 as Parameter Name (Since i am using ODBC)Size set to default -1.
In Result SetResult Name to 1Variable Name to tot_value.
If in the query I hard code 'MyVal' i get the correct result, however when I use ? to use my variable as a parameter, I always get a 0 returned.
Note that my tot variable is set to MyVal
Any clue of what I might be missing? Thanks in advance
select TOP 1 CAST('' + ISNULL((SELECT distinct type_of_transfer_code
FROM SYSTEM.history_program_transfer
WHERE type_of_transfer_value = ?),'') AS VARCHAR(100)) as type_of_transfer_code
FROM SYSTEM.table_facility_defaults
Related
I am trying to read a table having five rows and columns. I have used sql.eachRow function to read eachRow and assign the value to a String. I am getting an error "Groovy:[Static type checking] - No such property: MachineName for class: java.lang.Object"
My code:
sql.eachRow('select * from [MACHINES] WHERE UpdateTime > :lastTimeRead, [lastTimeRead: Long.parseLong(lastTimeRead)])
{ row ->
def read = row.MachineName
}
but MachineName is my column name. How can i overcome this error.
Using dynamic Properties with static type checking is not possible*.
However, eachRow will pass a GroovyResultSet as first parameter to the Closure. This means that row has the type GroovyResultSet and so you can access the value using getAt
row.getAt('MachineName')
should work. In groovy you can also use the []-operator:
row['MachineName']
which is equivalent to the first solution.
*) without a type checking extension.
If you Know the Column name you can just use the Below.
"$row.MachineName"
But if you don't Know column name or having some issue, still it can be accessed using an array of Select.
sql.eachRow('select * from [MACHINES] WHERE UpdateTime > :lastTimeRead, [lastTimeRead: Long.parseLong(lastTimeRead)])
{ row->
log.info "First value = ${row[0]}, next value = ${row[1]}"
}
I have a table tsk with 2 columns : a task id in number, and a task scope in XMLTYPE which can be like :
<scope>
<siteCode>2</siteCode>
<supplierCode>1111</supplierCode>
<contractCode>464</contractCode>
<orderNumber>85235478</orderNumber>
</scope>
But the elements under the tag may vary from one record to another
I need to select task ids which match some conditions in the scope.
For example :
select tskid
from tsk t
where xmlexists('$a/scope[siteCode = 2 and supplierCode = 111]' passing t.tskscope as "a");
As the scope may vary, I have a PL/SQL function taking a xml path p_xmlpath to look for, in varchar2 type.
So for example, p_xmlpath will be :
p_xmlpath := 'scope[siteCode = 2 and supplierCode = 1111]';
Then I want to run the query with XMLEXISTS to find the matching records.
I thought to do it with bind variables in the following way :
select tskid
from tsk t
where xmlexists('$a/$b' passing t.tskscope as "a", p_xmlpath as "b" );
By doing this, the query returns all records, without taking the condition with xmlexists.
Does someone know how to manage this, i.e. having a variable path to give to XMLEXISTS ?
Additional info : until now, I used the function existsNode and the following query was doing the job correctly:
select tskid
from tsk t
where existsnode(t.tskscope, p_xmlpath) = 1;
But on one hand existsNode is deprecated and on the other I noticed that in my situation the function xmlexists was noticeably faster than existsNode, that's why I would to switch to xmlexists.
Thanks in advance.
I don't think you can; it seems to only allow the search values to be variables, not the whole search condition.
As a workaround you could build the XPath at runtome with replace():
select tskid
from tsk t
where xmlexists(replace('$a/$b', '$b', p_xmlpath) passing t.tskscope as "a");
or build the XPath string as a variable if you'd rather not have a replace in there, and include the $a/ part:
p_xmlpath := '$a/' || p_xmlpath;
select tskid
from tsk t
where xmlexists(p_xmlpath passing t.tskscope as "a");
I've just started using microsoft access so I don't really know how to solve this. I would like to use an update query to add a value from a form to a value on a table.
I originally used the SUM expression which gave me an error saying it was an aggregate function.
I also tried to add the two values together (e.g [field1] + [field2]) which as a result gave me a value with both numbers together instead of adding them together.
The following is the SQL I'm using:
UPDATE Votes
SET Votes.NumVotes = [Votes]![NumVotes]+[Forms]![frmVote]![txtnumvotes]
WHERE (((Votes.ActID) = [Forms]![frmVote]![combacts])
AND ((Votes.RoundNum) = [Forms]![frmVote]![combrndnum]))
I want to add a value [txtnumvotes] a form to a field [NumVotes] from the table [Votes].
Could someone please help me?
You can specify the expected data type with parameters:
PARAMETERS
[Forms]![frmVote]![txtnumvotes] Short,
[Forms]![frmVote]![combacts] Long,
[Forms]![frmVote]![combrndnum] Long;
UPDATE
Votes
SET
Votes.NumVotes = [Votes]![NumVotes]+[Forms]![frmVote]![txtnumvotes]
WHERE
(((Votes.ActID) = [Forms]![frmVote]![combacts])
AND
((Votes.RoundNum) = [Forms]![frmVote]![combrndnum]))
Without the specification, Access has to guess, and that sometimes fails.
I am trying to get data from SAP for analysis using RFC_READ_TABLE. It returns Fields correctly. However, when trying to get the rows it returns zero rows.
theFunc = functionCtrl.Add("RFC_READ_TABLE") '
Dim returnFunc As Boolean
Dim returnParam As Object
Dim retTab As Object
theFunc.exports("query_table") = "MSKA"
theFunc.exports("DELIMITER") = ";"
theFunc.exports("NO_DATA") = "TRUE"
theFunc.exports("ROWCOUNT") = "50"
returnFunc = theFunc.call
retTab = theFunc.tables("DATA")
msgbox retTab.rows.count ' >>>>>> returns 0
Last step returns zero as records count. The table contains data.When I search for table FIELDS , it returns the table fields correclty.
Is this related to security issues?
Regards,
Waleed
You're not getting any data returned because you're populating the NO_DATA parameter (which should be a single character anyway, not TRUE, for example). You're also not providing a WHERE clause (in the OPTIONS table parameter).
From the function module definition:
If you provide NO_DATA with a value of a single space (or omit it, as a single space is the default value) as well as a valid WHERE clause in OPTIONS, you should get data returned.
I wanted to know how we could store the result of my select query on a variable.
#ppt2 = Ppt.select('slide_name').where('id=?',4)
#ppt1 = Ppt.update_all({:time2=>#ppt2},['id like ?','1'])
Here, slide_name and time2 are both text attributes of the same table ppt.
What happens on the above execution is that the time2 field in id=1 gets the value "#ppt2" whereas I want it to get the value of slide_name from id=4 which does not get stored in #ppt1.
In other words, how do I store the value of the select query in #ppt2 so that it can be used in the next line?
Any help is appreciated.
Call the slide_name method on your first result.
#ppt2 = Ppt.select('slide_name').find(4).slide_name