I need to convert INT to DATETIME, on SQL Server it would be:
select cast(convert(unix_timestamp,103) AS datetime)
on MySQL the syntax is:
select FROM_UNIXTIME(unix_timestamp)
But i need to make it engine independent(SQL Server, MySQL, T-sql and so on).
is it possible?
Maybe its possible to trick it in PHP?
<?php
$sql='select cast(convert(1350134926,103) AS datetime)';
$result = #mysql_query($sql);
if(!$result){
$sql=' select FROM_UNIXTIME(1350134926)';
$result = #mysql_query($sql);
if(!$result){...}
}
?>
Related
i am currently trying to execute the following SQL statement in ballerina.io against a MariaDB.
Plan SQL:
select * FROM testDB where test LIKE '%BA%';
I get a result set with all data.
ballerina.io:
var selectRet = testDB->select("select * FROM testDB where test LIKE '%?%'", testREC, "BA");
I get an empty result set.
versions:
ballerina --version
jBallerina 1.1.2
Language specification 2019R3
Ballerina tool 0.8.0
Is it possible to make a SQL statement with LIKE in ballerina.io?
Many greetings,
Martin
The parameter is passed to the query as a separate literal string, not as some kind of template variable. To surround it with wildcards, you need to use concat() in the query:
var selectRet = testDB->select(
"select * FROM testDB where test like concat('%', ?, '%')",
testREC,
"BA"
);
Or just concatenate the wildcards in your code (this looks a bit cleaner to me):
var selectRet = testDB->select(
"select * FROM testDB where test like ?",
testREC,
"%BA%"
);
I am new to VectorWise database.
I need to declare variable and pass value in it same like we do in a SQL Server database. Please help me how to do this in VectoreWise database. I am using Squirrel as SQL client.
I need to do it like we do in SQL Server:
Declare #name varchar (100)
set #name ='ABC'
select #name
Output: ABC
I am not particularly familiar with Actian Vector, so I'm not sure if it has a scripting language. I don't see declare as a supported statement.
If you only need a parameter in a single select, you can use a CTE. For your example:
with params as (
select 'ABC' as name
)
select params.name
from params;
I'm not sure if this helps you, but it might.
I need to know how to handle <> operator used with a parameter in where clause within a prepared statement. Can anyone please show me how to do something similar to 'WHERE field <>:parameter'. Thanks.
Edit : I did not remember to mention that MySQL is my database server.
Up until I discovered this, In ALL examples on the web, I had only seen '=' operator in WHERE clause of prepared statements. But I recently found out that ANY, and I mean ANY, operator logical operator works with prepared statement placeholders, not just '='. As an example, you could have:
<?php
$stmt = $dbHandle->prepare( 'SELECT * FROM table WHERE id <> :ID' );
$stmt->execute( array( ':ID'=> $id ) );
?>
OR even this
<?php
$stmt = $dbHandle->prepare( 'SELECT * FROM table WHERE id <= :ID' );
$stmt->execute( array( ':ID'=> $id ) );
?>
AND, as you may guess,
<?php
$stmt = $dbHandle->prepare( 'SELECT * FROM table WHERE id >= :ID' );
$stmt->execute( array( ':ID'=> $id ) );
?>
It looks logical that PDO should be able to do this but was not sure. So, it was a relief to me to discover this through experimentation. I had always wanted to do that in my code. I hope this saves someone some time.
when i write the sql in 2008:
declare #recieved int
--find the isJieShou int
select #recieved=isJieShou
from Prj_SignF
where Row_Guid=
(
select Row_Guid
from prj_specTechInterface
where intfaceID=#specTechInterface
)
if(#recieved==1)
--begin
--end
It hint that if(#recieved==1) = have a syntax error?
why?
You didn't specify your RDBMS but your problem is mostlikely because equality is done using single =
if(#recieved=1)
I store an XML string in a column in my SQL Server database. I'm trying to run an UPDATE statement that will make a certain field into Upper Case. I can do that easily during a SELECT but can't get it to work with an update.
This SELECT statement works
select Upper(XmlTest.value('(/CodeFiveReport/Owner/#UnitNumber)[1]', 'varchar(10)')) as UnitNumber
from uploadreport
But I want to update the XML as that permanently
Update table Set XmlString.Modify('replace value of (/Root/Node/#Field)[1] with ?
upper-case was added to SQL Server in SQL Server 2008, so there's no good solution prior to that unless you want to use cursors. The following works in SQL Server 2008:
declare #xml xml
set #xml = N'<CodeFiveReport><Owner UnitNumber="Mixed"/></CodeFiveReport>'
select T1.C1.value('upper-case((/CodeFiveReport/Owner/#UnitNumber)[1])', 'varchar(10)') from #xml.nodes('/') T1(C1)
SET #xml.modify('
replace value of (/CodeFiveReport/Owner/#UnitNumber)[1]
with xs:string(upper-case((/CodeFiveReport/Owner/#UnitNumber)[1]))
')
select #xml
Use the XQuery function upper-case