I had this code (which worked fine) in a calculated database that joined two SQL datasources:
select m.Email, m.SkuID,m.SkuName,l.Email,l.LastLogin,l.DocsAdded
from Licenses m
inner join ActivityReport l on l.Email = m.Email
Due to a bug in the reports API that provides incorrect information on LastLogin time information, I'm using the Users.get API and writing that information a new datasource (just the email of the user and their last login time). I want to join this with my other two data sources. Using the below code:
select m.Email, m.SkuID,m.SkuName,l.Email,l.DocsAdded,x.Email,x.LastLogin as LastLogin
from Licenses m
inner join ActivityReport l on l.Email = m.Email
inner join LastLogin x on x.Email = l.Email
I get the error:
License save batch failed: JDBC backend failure. More information: Failed to execute connection with error: Deadlock found when trying to get lock; try restarting transaction
I also get two errors that looks like this:
License save batch failed: Malformed SQL. More information: Error with SQL statement: Duplicate entry 'user#email.com' for key 'PRIMARY'.
What am I doing wrong?
I'm thinking you might need to add 'as' in your inner join unless you have already declared this in part of your code that was not posted.
from Licenses **as** m
inner join ActivityReport **as** l on l.Email = m.Email
inner join LastLogin **as** x on x.Email = l.Email
The second error is saying that you have more than one entry that your trying to join on. So you might consider trying to join on something that has unique entries to ensure you don't have duplicates in your join.
There is no issue in your query , query is right but this is deadlock issue ,So when many threads are running on server ,for example:
Deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process. So In case of deadlock, system automatically cancelled less expensive query.
If you try after sometime there will be no issue and therefore no error prompt.
Related
I am working on a piece of SQL for a IBM U2 Rocket database. It's not a flavour of db platform I'm familiar with.
I do not have direct access to this database: I can only access it by composing statements in the calling code and testing it from there. That makes it kind of awkward to figure out where the problem is when there are syntax errors.
I'm trying to compose a query which has a condiational on a dervied column. As far as I can tell from what I've read about the database, this ought to work:
SELECT a.*
FROM (
SELECT dp.NAME
,dp.Code
,dp.BusinessType + ts.BusinessType AS bType
FROM dataPoints dp
LEFT OUTER JOIN trialSuppliers ts
WHERE ts.AccountStatus = 'A'
) a
WHERE a.bType LIKE '%cho%'
However, it throws this error:
Died in UCI::SQLExecDirect() with SQLSTATE 37000, Native error:0
[IBM][SQL Client][UNIDATA]
If you just run the inner query, it works fine. Trying to use any kind of inner select statement causes it to throw the same error, i.e. this:
SELECT *
FROM (
SELECT dp.NAME
,dp.Code
,dp.BusinessType + ts.BusinessType AS bType
FROM dataPoints dp
LEFT OUTER JOIN trialSuppliers ts
WHERE ts.AccountStatus = 'A'
)
Still fails.
What's the correct syntax to be able to filter my query by the derived column?
Just doing some clean-up, did the last comment resolve the issue?
I am not a UniData user but in its half cousin UniVerse the "from clause" has to be a table. You have to do sub-queries in the where clause. I would do what you want to do adding a couple of I-descriptors in the dictionary. I have often found the limited SQL compliance of the U2 products to be somewhat of a hindrance, but when your metadata is external to and separate from your data you are going to lose a bit of structured query sanity. – Van Amburg Sep 21 '17 at 17:31
Using Crystal Reports version 13.0 in Visual Studio 2010.
Using the Command feature, all the fields needed are selected.
One of the fields is from a separate database on the same server.
SELECT r.ID, r.Revision,
u.FirstName + ' ' + u.LastName AS UpdateBy, r.UpdateDate,
s.Description AS Status, r.StatusID, r.Comments,
c.Notes
FROM Repel r
INNER JOIN Status s ON r.StatusID = s.id
INNER JOIN Conditions c ON c.SOCID = r.ID
LEFT OUTER JOIN [Admin].[dbo].[Users] u ON u.ID = r.UpdateBy
WHERE r.ID = {?item}
Using the database expert, both databases are connected but the command itself is on the main datasource.
The datasource with the tables Repel, Status, and Conditions.
It can NOT find the table Users.
The path is fully qualified so how can I get the report to see this table?
I know I could create a view in sql server itself and connect to that but there is a change that needs to be made to 30+ reports.
Thanks!!
EDIT
I tried to create a view in the main database only to use one datasource.
Then changed the line...
LEFT OUTER JOIN vUsers u ON u.ID = r.UpdateBy
Now I get the error:
This field name is not known.
Final EDIT
Doing more testing, I removed all database connections and fields from the report.
The unknown field name still appeared.
So, I removed everything from the report - still had the error.
Copied the text fields to a brand new report and added the database and command.
The error is now gone and the report is working.
Very strange.
I got report from another team about blocking in SQL Server. Looking at results of
Exec sp_who2
and query from blog by Glenn Berry
SELECT blocking.session_id AS blocking_session_id
,blocked.session_id AS blocked_session_id
,waitstats.wait_type AS blocking_resource
,waitstats.wait_duration_ms
,waitstats.resource_description
,blocked_cache.text AS blocked_text
,blocking_cache.text AS blocking_text
FROM sys.dm_exec_connections AS blocking
INNER JOIN sys.dm_exec_requests blocked
ON blocking.session_id = blocked.blocking_session_id
CROSS APPLY sys.dm_exec_sql_text(blocked.sql_handle) blocked_cache
CROSS APPLY sys.dm_exec_sql_text(blocking.most_recent_sql_handle) blocking_cache
INNER JOIN sys.dm_os_waiting_tasks waitstats
ON waitstats.session_id = blocked.session_id
I want not able to catch anything being blocked. Running this multiple time I start to notice that something shows up but next time I run query, blcoking is gone.
I created temp table by SELECT INTO
,blocking_cache.text AS blocking_text
INTO #TempBlockingTable
FROM sys.dm_exec_connections AS blocking
After that modified query to be INSERT INTO SELECT. Now I was able to run query as many times as I want without fearing that results would be gone.
I kept running query for about 10 seconds until I finally got some results.
SELECT * FROM #TempBlockingTable
Looking at resource_description column from sys.dm_os_waiting_tasks I found that data is displayed in the following format.
<type-specific-description> id=lock<lock-hex-address> mode=<mode> associatedObjectId=<associated-obj-id>
Microsoft documentation on sys.dm_os_waiting_tasks http://technet.microsoft.com/en-us/library/ms188743.aspx does not have definition for associatedObjectId
Answer actually comes from Aaron Bertrand found it on Google Groups. To Get OBJECT_NAME of associatedObjectId you need to run the following query
SELECT OBJECT_NAME([object_id])
FROM sys.partitions
WHERE partition_id = 456489945132196
This number 456489945132196 represents value of associatedObjectId from resource_description column from sys.dm_os_waiting_tasks
I am in the middle of creating a new database for mobile phones. It includes a lot of information regarding mobile phones, sim cards etc. I am struggling to get the information in the tables converted into a view. I have done a few tests but always receive an error on certain columns. For example, one of the fields is the sim card number which you'll all know is a long number. I have tried having this number as bigint, varchar and nvarchar but always receive an error saying "the conversion of the varchar value 'value' has overflowed an int column. Maximum integer value exceeded".
I have a decent level of knowledge when it comes to databases but for some reason I just can't seem to find the right data type for these fields. If someone who has a lot more experience in this could help me out, it would be much appreciated.
Thanks in advance.
SELECT dbo.Sims.Number,
dbo.Sims.ACCOLC,
dbo.Users.Title,
dbo.Users.Name,
dbo.Users.Section,
dbo.Users.Directorate,
dbo.UserHistory.StartDate,
dbo.UserHistory.EndDate,
dbo.Users.Codes
FROM dbo.UserHistory
INNER JOIN dbo.Users
ON dbo.UserHistory.[User] = dbo.Users.ID
INNER JOIN dbo.Sims
ON dbo.UserHistory.Number = dbo.Sims.Number
INNER JOIN dbo.Models
ON dbo.UserHistory.Model = dbo.Models.ID
The one thing that I might suggest is to check if you in fact want an INNER JOIN between each table. That requires matching rows in all tables, if you do not have the matching row then you won't get a result.
You might want to try changing the JOIN type to a LEFT JOIN:
SELECT s.Number,
s.ACCOLC,
u.Title,
u.Name,
u.Section,
u.Directorate,
uh.StartDate,
uh.EndDate,
uh.Codes
FROM dbo.Users u
LEFT JOIN dbo.UserHistory uh
ON u.ID = uh.[User]
LEFT JOIN dbo.Sims s
ON uh.Number = s.Number
LEFT JOIN dbo.Models m
ON uh.Model = m.ID
This version will return all users even it there are not matching rows in the other tables.
I have a large table User and a small table User_purchase in google bigquery.
If I join the two with
SELECT User.id, User_purchase.amount FROM User
LEFT JOIN User_purchase on User.id = User_purchase.user_id,
the query returns error:
Query Failed. Error: Not Implemented: This table cannot be read
But if I join the two with
SELECT User.id, ISNULL(INTEGER(User_purchase.amount), INTEGER(0)) FROM User
LEFT JOIN User_purchase on User.id = User_purchase.user_id,
the query works.
Don't quite understand why the first case does not work.
I assume in the first case I can get all users with their purchase_amount though some users will have NULL as their purchase_amount.
Thanks.
This is a bug relating to nested field names in query replies. I've got a fix for the bug but it won't go out until next week's release. Thanks for bringing it to our attention.