Why is FORMAT function not recognised? - sql-server-2012-express

I have executed the following query:
SELECT productid,
FORMAT(productid, 'd10') AS str_productid
FROM Production.Products;
I it is sayng that 'FORMAT' is not a recognized built-in function name.
I am using the TSQL2012 database and Microsoft SQL Server 2012 Express.
Can some one tell me what is wrong? The Express verssion has not included Format function?

Try this
ALTER DATABASE database_name
SET COMPATIBILITY_LEVEL = 110
here are details

Related

sql query with in clause in oledb source ssis

Hope everyone is doing well. I am new in ssis and I am badly stuck.
I have a ssis package which has a Oracle oledb source and sql server oledb destination. The oracle oledb source has a parameterized sql query .
I have a string variable #resultset with a list of comma seperated id's which I have parsed from an execute sql task object variable. value of #resultset is like this 111,2222,333,444
I need to feed this string variable to the in clause in the parameterized source query.
I am using sql command from variable in the oledb source. I have stored the query as expression in a variable called #setquery.
The query is like this:
"select col1, col2, ...coln from oracledb.table
where colid in (" + #resultset + ")"
But I get an error when I try to see the columns."Unable to retrieve column information from data source"
I read that I can use dynamic sql and I tried it but I am not being able to do it right.
I am using sql server 2017 and visual studios for ssdt 2017.
Could you please help!!
Thank you!
try to set the OLEDB Setting : AlwaysUseDefaulCodePage to True!
Good luck

How to create an APEX_COLLECTION?

I want to create an apex_collection in the Oracle SQL Developer for my apex webapplication.
Here's my code:
apex_collections.create_or_truncate_collection('TEST');
After running the statement I get the following:
If I enter the select-statement:
SELECT *
FROM apex_collections
WHERE collection_name = 'TEST';
afterwards, I get this:
It seems to me that no collection has been created,although there is no error code. What am I doing wrong? Why is the collection not created? I also tried to run the statement in the SQL Workshop of Oracle APEX, but the command is unknown there. I am using Oracle 12c version.
You will need a valid APEX session to create the collection. If you are on APEX 18.1 or later, use the procedure apex_session.create_session (see documentation) to create one. Make sure that the app_id is valid for the workspace that your schema is assigned to.
For anything before 18.1, OraOpenSource oos-utils has a procedure that does the same: oos_util_apex.create_session (see code). You will need to install oos-utils, or at least compile this package in your schema. Alternatively, replicate the activity contained in this procedure.
Update: Also, I just noticed Jeff Smith's comments. You will need to add members to the collection in order to get meaningful results.
begin
apex_session.create_session(
p_app_id => 100
, p_page_id => 1
, p_username => 'somebody'
);
end;
/
select * from apex_collections; -- shows nothing
begin
apex_collection.create_or_truncate_collection(
p_collection_name => 'test'
);
apex_collection.add_member(
p_collection_name => 'test'
, p_c001 => 'test row'
);
end;
/
select * from apex_collections; -- shows one record
Also, if you are using SQLDEV to troubleshoot the collections in an APEX session, then you'll want to use either the apex_session.attach or oos_util_apex.join_session procedure, depending on the version of APEX you are running. Use the APEX Session ID assigned to your browser session.
HTH.

PostgreSQL: Equivalent way to express the following Oracle SQL, HH.MI.SSXFF AM

The oracle script I'm in the process of 'converting' so it can be executed in PGAdmin4, has the following values to insert into a column of table with a data type of 'date'
to_timestamp('12-JUN-99','DD-MM-YY HH.MI.SSXFF AM')
From my understanding, FF represents Fractional Seconds.
What would be the equivalent way to represent the statement in PostgreSQL/PGAdmin 4?
SSXFF is my main concern.
I don't see how that code works in Oracle. But this should work in both Postgres and Oracle:
select to_timestamp('12-JUN-99', 'DD-MON-YY')

Query referencing aliased column in order by in SQLServer 2012

I have a SQL Select query that's embedded in a piece of C# code which I don't want to change. My problem is that the query executes fine on SQLServer 2008 but not 2012.
The offending line of code is:
Select code as SiteCode from TimeSheetContracts S order by S.SiteCode
Executed in a database on SQL2008 it works fine. The same database upgraded to SQLServer 2012 errors with the following...
Msg 207, Level 16, State 1, Line 2
Invalid column name 'SiteCode'.
If I edit the query to be
Select code as SiteCode from TimeSheetContracts S order by SiteCode
it works fine. Can anyone explain this?
There is no column in TimeSheetContracts called SiteCode, so a reference to s.SiteCode is not valid. Aliasing in ORDER BY is a little more strict since SQL Server 2000, when the syntax was a little more forgiving. The only way s.SiteCode would have worked on your SQL Server 2008 instance was if your database was in COMPATIBILITY_LEVEL = 80 (go ahead and try it on a different database that is 90 or greater). Once you move to SQL Server 2012, 80 is no longer an option. On a 2005, 2008 or 2008 R2 instance, try this:
CREATE DATABASE floob;
GO
USE floob;
GO
CREATE TABLE dbo.SalesOrderHeader(SalesOrderID INT);
GO
SELECT SalesOrderID AS ID FROM dbo.SalesOrderHeader AS h ORDER BY h.ID; -- fails
GO
ALTER DATABASE floob SET COMPATIBILITY_LEVEL = 80;
GO
SELECT SalesOrderID AS ID FROM dbo.SalesOrderHeader AS h ORDER BY h.ID; -- works
GO
USE master;
GO
DROP DATABASE floob;
If you want to use the column alias, you'll need to (and should always have been) just use the alias. If you want to use the table alias prefix, you'll need to use s.code.

Query from QSYS2.SysTables returns error "Token; void"

I am trying to read data from AS400 DB using Excel, VBA and ODBC driver. Connection is successful but none of the queries are retrieving data from DB. For ex: The select query is not working:
select * from QSYS2.SysTables;
The Client gets the following error message:
[IBM] [System i Access ODBC Driver] [DB2 for i5/OS] SQL0104 - Token; void. Valid tokens: <END Instruction>.
What is wrong with my query?
Edit: I am trying to read data from AS400 only not from DB2. I want to read the table names from SysTables(system table).
Remove the statement termination character (;) for a single statement execution.
This is an example for retrieving queries:
"Select * from Tablename";
If it doesn't work, try checking the manual for query in Microsoft. It's different from standard SQL queries.