Is it possible to force Business Objects 6.5 to create proper ANSI joins? - sql-server

The SQL that Business Objects generates seems to be stuck in a bygone era for SQL joins -- it insists on using the old Sybase outer-join syntax (*=, etc.), which is illegal in SQL Server 2005 when running at level 90. Is there an option somewhere to make it use modern join syntax (i.e., joining using the JOIN keyword rather than using commas in the FROM statement)?

From memory, there's a universe parameter called ANSI92 that does exactly what you want.

Related

IS NOT NULL AS ... - Convert Query from MySQL to MS-SQL

I have an application that is working fine using a MySQL/MariaDB-Database.
I did make it more flexible and now I am basically able to use a Microsoft SQL-Server database.
I found out, that some SQL-queries do NOT work anymore.
I don't have experience with MS-SQL and I am looking for support to convert the following query to make it work with MS-SQL. It would be great, if the query could be converted to work in both MS-SQL and MySQL ...
I have created an SQL-Fiddle with some example-data.
Link: http://sqlfiddle.com/#!18/5fb718/2
The Query itself looks like this:
SELECT computermapping.PrinterGUID, computerdefaultprinter.PrinterGUID IS NOT NULL AS isDefaultPrinter
FROM computermapping
LEFT JOIN computerdefaultprinter ON computerdefaultprinter.ComputerGUID = computermapping.ComputerGUID
AND computerdefaultprinter.PrinterGUID = computermapping.PrinterGUID
WHERE computermapping.ComputerGUID = "5bec3779-b002-46ba-97c4-19158c13001f"
When I run this on SQL-Fiddle I get the following error:
Incorrect syntax near the keyword 'IS'.
When I run this Query in Microsoft SQL Server Management Studio I get the same Error. I have an German-Installation ...
Meldung 156, Ebene 15, Status 1, Zeile 1
Falsche Syntax in der Nähe des IS-Schlüsselworts.
I was looking on the Internet to find information on how to use the IS NOT NULL AS in MS-SQL. Maybe I was using the wrong keywords, but I was not able to find a solution myself.
If it does matter, I am using "SQL-Server 2014 SP3" at the moment.
Thank you
Convert
computerdefaultprinter.PrinterGUID IS NOT NULL AS isDefaultPrinter
to
CASE
WHEN computerdefaultprinter.PrinterGUID IS NOT NULL THEN 1
ELSE 0
END AS isDefaultPrinter
Demo here
Also bear in mind that there is no BOOLEAN type in SQL Server. BIT type is used instead.
Finally
WHERE computermapping.ComputerGUID = "5bec3779-b002-46ba-97c4-19158c13001f"
should be converted to
WHERE computermapping.ComputerGUID = '5bec3779-b002-46ba-97c4-19158c13001f'
since the single quote character is used to delimit strings in SQL Server
MySql evaluates boolean expressions like:
computerdefaultprinter.PrinterGUID IS NOT NULL
as 1 for TRUE or 0 for FALSE.
SQL Server does not do such an evaluation, so you need a CASE expression:
CASE WHEN computerdefaultprinter.PrinterGUID IS NOT NULL THEN 1 ELSE 0 END
The exact question was already answered, but you should really, really try using the SQL Server Migration Assistant for MySQL. No database supports the SQL standard beyond a basic compatibility level and MySQL is one of the quirkiest databases when it comes to SQL compatibility.
The SQL standard process is sloooow so all vendors implement features long before they're standardized. Different databases have different priorities too, and MySQL's priority for the first decade at least wasn't enterprise applications, so SQL compatibility wasn't a high priority.
Some common features were added only in MySQL 8. Some hacks allowed (but discouraged) in MySQL, like non-aggregate columns in a grouping query, or quirky updates to calculate row numbers, don't work in any other databases because logically, they lead to unpredictable results.
Even in MySQL, non-aggregate columns can cause serious performance degradation when upgrading from one 5.x version to the next. There's at least one SO question about this.
The Migration assistant will convert tables and types where possible and flag any stored procedure or view queries that can't be translated. It can also copy data from an existing MySQL database to a SQL Server database

SQL query looks OK in management studio but throws memory exception when building reports by Data Tools

I have fours SQL tables (with different number of rows and column) from those I want to build a new table for reporting purpose based on some rules. I built query statements and run in management studio. In this case, I get some response from management studio with some data but if I try to use those SQL queries in data source to build a report in Visual Studio, I get memory exception. What can I do for this?
Here is the SQL statements I used
SELECT Intable.Fra, EqTable.Name, Rf.Data
FROM EqTable,InTable,RfTable
WHERE RfTable.Name = EqTable.Name AND EqTable.Name] NOT LIKE '%Ann%';
The equivalent tables are shown in the following diagram.
I can see two possibilities:
You have an additional "]" character included in your SQL but this maybe a typo
Do you need a join for the table [inTable]?
This is almost certainly because you are using the ANSI-89 style join. You should use the "newer" ANSI-92 style join.
Bad habits to kick : using old-style JOINs
What has happened here is you have joined RfTable and EqTable by Name. But then you have created a cross join to InTable. The memory exception is probably because once you create this cross join the amount of rows is staggering.
What I really don't understand though is you said you have 4 tables but only 3 of them are in your query.

Questions in Sybase lag and over by concept

I have table like this below in my sybase database
ID,Col1,Col2
1,100,300
2,300, 400
3,400,500
4,900,1000.
I want result like this below only in sybase.
1,100,500 --- cross interrow checking the values
2,900,1000.
SInce you did not specify which database you're using, I'm assuming your using Sybase ASE (rather than Sybase IQ or Sybase SQL Anywhere, which do support lag/lead etc.)
Also it's not quite clear what you want since you have not defined how the relation between the various rows and columns should be interpreted. But I'm guessing you're essentially hinting at a dependency graph between Col2->Col1.
In ASE, you'll need to write this as a multi-step, loop-based algorithm whereby you determine the dependency graph. Since you don't know how many levels deep this will run, you need a loop rather than a self-join. You need to keep track of the result in a temporary table.
Can't go further here... but that's the sort of approach you'll need.

Get SQL Server 2005 sort varchar columns just as Java would do

My problem is very simple: I have an array of String. Sorting it in Java gives one order , and in Sql Server 2005 slightly different order . An example of difference I spotted was in the case of two strings: "jyl ; pagespro" , "jyl" , which Java sorts in this order, and Sql in the inverse order .
I tried to make Sql Server order by ascii(myColumn) but still with no effect. How can I solve this ??.....
To extend on DaveE's answer, if you have determined the collation you want to use for sorting, you can use its name in the ORDER BY clause like this:
ORDER BY colA COLLATE SQL_Latin1_General_Cp437_CS_AS_KI_WI.
Please be aware that this would not use an index for sorting that might be defined on colA. You could get around that by using calculated columns.
In general, I would suggest to do all sorting in one place: either in Java, or in the database, but not sometimes here and sometimes there. This just leads to confusion and complexity.
I'd suspect it has to do with the SQL Server collation in effect. That affects not only the available character set but also how the characters sort against one another. Even in the fairly generic SQL_Latin1_General family, there are dozens of specific collations available.

Sql Server: all object dependencies

Is there any place where I can find all possible object type dependencies in Sql Server?
What I mean by "object dependency" is a list of object that one object can depend on. For example, TABLE can depend on SCHEMA, TYPE, TABLE, FUNCTION, etc.
Aside from dynamic SQL, technically, SQL Server does keep track of dependencies. However, until SQL Server 2008, its tracking was not reliable because it only updated dependencies if all dependent entities existed at time of creation. SQL Server 2008 significantly improved dependency tracking.
In SQL Server 2000 and 2005, you can query against sys.sql_dependencies to get a list of dependencies.
In SQL Server 2008, you should use sys.sql_expression_dependencies See sys.sql_expression_dependencies for more.
EDIT I think I may have misinterpreted your question. It sounds like you are looking for a list of object types on which a TABLE type object can depend. Directly or indirectly, it would be any object type in the system. If we only want "direct" dependencies, then it depends on what is meant by "direct". For example, does a trigger that references a view count as a direct dependency of the trigger table to the view?
EDIT As far as I know, there is no enumerated list of all possible dependencies between types. The best that you could achieve is to analyze the types that do depend on other types in a given database using something like:
Select DependentObj.Type, ReferencedObj.Type
from sys.sql_dependencies As D
Join sys.sysobjects As ReferencedObj
On ReferencedObj.id = D.referenced_major_id
Join sys.sysobjects As DependentObj
On DependentObj.id = D.object_id
Group By DependentObj.Type, ReferencedObj.Type
For actual objects (what objects does table 'foo' depend on):
sys.sql_dependencies
Is mostly accurate. There is also the SMO helper, DependencyWalker.
As a general type question (ie. what type of objects can a table depend on), you just need to go through the spec on MSDN for each object CREATE/ALTER statement and read carefully everything.
A persisted computed column in a table could depend on a user defined function.
A non-deterministic user-defined function can depend on a table.
A constraint could cause a table to depend on a table.
ad nauseum.
You could pick any pair of object types and we might be able to come up with a dependency.
There are obviously some restrictions in the various SQL Server features, but I'm not aware of any comprehensive matrix of all possible allowed and disallowed dependencies.

Resources