MSSQL 2014 Format function is not recognized - tsql

I'm using MicrosoftSQL Server 2014 and Management Studio version 12.0.4100.1 and trying to use Format function to do the following:
Format([money spent], 'C', 'en-us') as 'You Spent'
When executing that statement I get the following error:
'format' is not a recognized built-in function name.
I tried to change compatibility level as well, changing to 110 did not work by saying that Valid values of the database compatibility level are 80, 90, or 100
Is there is an alternative that I can use to achieve the same result, or I still can use Format function after changing some other settings?

Since FORMAT() is not supported in 2008 you have to manually format. You can try something like
SELECT '$' + CAST(ROUND([money spent], 2) AS VARCHAR(25))

Related

Compare stored procedure in SQL Developer - set NLS_CHARACTERSET for match accent marks

I'm using SQL Developer for compare a stored procedure (from the database) with a .sql file. This stored procedure and .sql file has spanish mark accents.
I do this comparasion using SQL Developer, by following these steps:
Right-click on the body of the stored procedured from the database.
select compare option.
select with other file option.
The problem I'm facing is that both (the stored procedure from the database AND the .sql file) has accent marks in spanish:
Example:
UPDATE T_BH_ADMIN_COM_LOAD
SET T_COBSERVATION = 'Observación debe contener mínimo 10 caracteres'
WHERE NVL(TRIM(OBSERVACION), '') IS NOT NULL
AND LENGTH(TRIM(OBSERVACION)) < 10
AND TRIM(ACL_COBSERVATION) IS NULL;
Where:
Observación debe contener mínimo 10 caracteres
Translated:
Observation must have minimum 10 characters
When I select the compare feature from SQL Developer, I got these results:
Spanish mark accents shows interrogation mark in compare window result:
When I execute this query I found in this answer:
select * from v$nls_parameters where parameter = 'NLS_CHARACTERSET';
The results are:
PARAMETER
VALUE
NLS_CHARACTERSET
WE8ISO8859P1
I wondering how I can compare the files using SQL Developer and avoiding the encoding differences.
I share the "SQL Developer about" information:
Oracle SQL Developer 4.1.3.20
Versión 4.1.3.20
Versión Interna MAIN-20.78
IDE Version: 12.2.1.0.42.151001.0541
Product ID: oracle.sqldeveloper
Product Version: 12.2.0.20.78
Versión
-------
Componente Versión
========== =======
Oracle IDE 4.1.3.20.78
Plataforma Java(TM) 1.8.0_60
Soporte de Control de Versiones 4.1.3.20.78
NLS Preferences in SQL Developer:
For now, I'm using other tool for compare files - using Visual Studio built-in feature for compare files - link to the answer with more details, in this case, I have to copy/paste the results in plain text files and execute this feature, but, those are extra steps I want to avoid in the near future.
Is there anything I can do for use the compare feature from SQL Developer as I intend?

SQL Anywhere v10 Syntax error near OUTPUT

I'm attempting to output a table to an outside file. I've found a few questions regarding this and followed the answers from there without any luck.
SELECT *
FROM transactions;
OUTPUT TO 'C:\Users\administrator\Desktop\Test.txt'
Is the statement I've been using, I've attempted different variations with formatting and file types such as .csv with no change.
Which produces:
ErrorCode : 102
SQLState : 42W04
Message : SQL Anywhere Error -131: Syntax error near 'OUTPUT' on line 1
SQL =
OUTPUT TO 'C:\Users\administrator\Desktop\Test.txt'
Appreciate all your help
Are you running this through dbisql, or in a different application? OUTPUT TO is a dbisql command, not a SQL statement recognized by the database server. You can use the UNLOAD statement in any application to allow the server to create the file.
Disclaimer: I work for SAP in SQL Anywhere engineering.

Sybase: Incorrect syntax near 'go' in a 'IF EXISTS' block

This is my sql statement
IF EXISTS (select 1 from sysobjects where name = 'PNL_VALUE_ESTIMATE')
drop table dbo.PNL_VALUE_ESTIMATE
go
isql bails out with this error message
Msg 102, Level 15, State 1:
Server 'DB_SERVER', Line 3:
Incorrect syntax near 'go'.
But the sql statement look correct to me. What's wrong?
Sybase version is 15
Try this:
IF EXISTS (select 1 from sysobjects where name = 'PNL_VALUE_ESTIMATE')
drop table dbo.PNL_VALUE_ESTIMATE
go
or this:
IF EXISTS (select 1 from sysobjects where name = 'PNL_VALUE_ESTIMATE')
BEGIN
drop table dbo.PNL_VALUE_ESTIMATE
END
go
or this:
IF EXISTS (select 1 from sysobjects where name = 'PNL_VALUE_ESTIMATE')
BEGIN
select 1
END
go
Does any work?
GO is not a keyword of T-SQL, but of the editor.
SMSS (between others) uses it as 'division' between batches of commands it sends to the database server. Executing it inside a stored procedure, or even a script file, won't work.
edit: Maybe it works with SyBase, but I think it'll need to be uppercase in that case.
From the documentation, the GO statement is a command of the editor you're using, not SQL itself:
GO is not a Transact-SQL statement; it is a command recognized by the
sqlcmd and osql utilities and SQL Server Management Studio Code
editor.
That said - Sybase is also an editor that supports the GO statement.
I've had the same problem, but with SQL Management Studio. The issue is that the editor does not support mixed-newline types around certain statements - GO being one of them. In Management Studio, for example, only Windows-style newlines (CR + LF) are allowed and if I were to use the Linux format (LF), it will give the exact same error as yours above.
Text-editors such as Notepad++ (what I use) have an option for what type of End-of-Line characters you use by default (Windows, Linux, Mac (CR)).
Try checking what newline character(s) are being used in your statements to see if that can fix the problem.
Shouldn't the object reference have
dbo..PNL_VALUE_ESTIMATE
because you haven't given a database name, and if you include the obj owner you need .. to miss the db name?
I'd go:
EXEC('DROP TABLE dbo..PNL_VALUE_ESTIMATE')
in the true part as well, because DROP TABLE is always compiled, and if the table isn't there you'll still have a failure.
Do you even need dbo? If your sql always runs as dbo just leave it out.

How to collect column headers and data using dbisqlc.exe command

I am trying to query a Sybase ASA database using the dbisqlc.exe command-line on a Windows system and would like to collect the column headers along with the associated table data.
Example:
dbisqlc.exe -nogui -c "ENG=myDB;DBN=dbName;UID=dba;PWD=mypwd;CommLinks=tcpip{PORT=12345}" select * from myTable; OUTPUT TO C:\OutputFile.txt
I would prefer it if this command wrote to stdout however that does not appear to be an option aside from using dbisql.exe which is not available in the environment I am in.
When I run it in this format the header and data is generated however in an unparsable format.
Any assistance would be greatly appreciated.
Try adding the 'FORMAT SQL' clause to the OUTPUT statement. It will give you the select statement containing the column names as well as the data.
In reviewing the output from the following dbisqlc.exe command, it appears as though I can parse the output using perl.
Command:
dbisqlc.exe -nogui -c "ENG=myDB;DBN=dbName;UID=dba;PWD=mypwd;CommLinks=tcpip{PORT=12345}" select * from myTable; OUTPUT TO C:\OutputFile.txt
The output appears to break in odd places using text editors such as vi or TextPad however the output from this command is actually returned with specific column widths.
The second line of the output includes a set of ='s signs which are contained for the width of each column. What I did was build a "template" string based on the ='s which can be passed to perls unpack function. I then use this template to build an array of column names and parse the result set using unpack.
This may not be the most efficient method however I think it should give me the results I am looking for.

Netbeans SQL select column names with # in the

I have an odd problem with netbeans (6.7.1). Using the built in SQL editor I cannot select any column defined with a # in it's name. It appears that Netbeans is treating this a comment and never passing to the underlying connection. Is there a way to change this?
Thanks,
David
If you have any control over the column names, I suggest you remove the # symbols. NetBeans is not the only application that will choke on them.