Katalon Studio SQL Query case statement - sql-server

I'm working with Katalon Studio for web testing automation.
I'm using data from database for user login, and I had to difference from ORMA_PROFESSIONALS.PROF_SURNAME_2 that are written with a white space. But when I use this query in Katalon Studio SLQ Query, I get that message below.
I use the same Query in SQL Server Management 2016 and I don't recieve any problems.
SELECT SECU_USERS.USER_LOGIN as login,
ORMA_PROFESSIONALS.PROF_NAME
+' '+ ORMA_PROFESSIONALS.PROF_SURNAME_1
+''+case ORMA_PROFESSIONALS.PROF_SURNAME_2
when '' then ''
else ' '+ORMA_PROFESSIONALS.PROF_SURNAME_2
end
as name
FROM SECU_USERS
inner join ORMA_PROFESSIONALS on
SECU_USERS.PROF_ID=ORMA_PROFESSIONALS.PROF_ID
Error:
com.microsoft.sqlserver.jdbc.SQLServerException: Unable to identify the table SELECT SECU_USERS.USER_LOGIN as login,
ORMA_PROFESSIONALS.PROF_NAME
+' '+ ORMA_PROFESSIONALS.PROF_SURNAME_1
+''+case ORMA_PROFESSIONALS.PROF_SURNAME_2
when '' then ''
else ' '+ORMA_PROFESSIONALS.PROF_SURNAME_2
end
as name
FROM SECU_USERS
inner join ORMA_PROFESSIONALS on
SECU_USERS.PROF_ID=ORMA_PROFESSIONALS.PROF_ID para los metadatos.
Query: SELECT SECU_USERS.USER_LOGIN as login,
ORMA_PROFESSIONALS.PROF_NAME
+' '+ ORMA_PROFESSIONALS.PROF_SURNAME_1
+''+case ORMA_PROFESSIONALS.PROF_SURNAME_2
when '' then ''
else ' '+ORMA_PROFESSIONALS.PROF_SURNAME_2
end
as name
FROM SECU_USERS
inner join ORMA_PROFESSIONALS on
SECU_USERS.PROF_ID=ORMA_PROFESSIONALS.PROF_ID Parameters: []

Related

Who (Or What) ran this query ID

I'd like to know who (Service account, user account ,etc ) ran each query_id that Query_Store records. Is there a way to do this? I've looked all over and can't seem to find anything.
Basically I'd like the data from this to be stored as well. Hostname, and Login Name are very useful to me.
SELECT sdest.DatabaseName
,sdes.session_id
,sdes.[host_name]
,sdes.[program_name]
,sdes.client_interface_name
,sdes.login_name
,sdes.login_time
,sdes.nt_domain
,sdes.nt_user_name
,sdec.client_net_address
,sdec.local_net_address
,sdest.ObjName
,sdest.Query
FROM sys.dm_exec_sessions AS sdes
INNER JOIN sys.dm_exec_connections AS sdec ON sdec.session_id = sdes.session_id
CROSS APPLY (
SELECT db_name(dbid) AS DatabaseName
,object_id(objectid) AS ObjName
,ISNULL((
SELECT TEXT AS [processing-instruction(definition)]
FROM sys.dm_exec_sql_text(sdec.most_recent_sql_handle)
FOR XML PATH('')
,TYPE
), '') AS Query
FROM sys.dm_exec_sql_text(sdec.most_recent_sql_handle)
) sdest
where sdes.session_id <> ##SPID
--and sdes.nt_user_name = '' -- Put the username here !
ORDER BY sdec.session_id
Credit: Execution datetime for SQL queries against SQL Server
There's no DMV that records which sessions ran which queries. To gather that information you must use an Extended Events trace, or a Database Audit.

SQL Server Linked Server openquery for WHERE clause

I am trying to write a query to get the delta between my server and Linked Server. So I wrote the following which worked until:
Select MD5 FROM ServerA A
WHERE NOT EXISTS
(
SELECT 1
FROM [LinkedServer].[Database].[dbo].[Files] fi
WHERE A.MD5High = fi.MD5High AND A.MD5Low = fi.MD5Low
)
However this pulls all the data from LinkedServer to my server which causes my server to run out of resources. So my next attempt was to perform the query on the linked server
Select MD5 FROM ServerA A
WHERE NOT EXISTS
(
SELECT 1
FROM OPENQUERY( [LinkedServer] , 'SELECT [LinkedServer].[Database].[dbo].[Files] fi
WHERE fi.MD5High = ' + A.MD5Low + ' AND fi.MD5Low= ' + a.MD5Low + '')
)
However the syntax in the second query is incorrect and I can't figure the correct syntax.
I appreciate any direction

Get subscriber's name from SSRS database

what I am trying to do is creating a report about failed subscriptions in MS SQL Server Report Server (SSRS). What I have done so far is the following SQL statement:
USE ReportServer
GO
WITH SubscriptionsCTE AS
(
SELECT
c.[Name],
c.[Path],
s.[Description],
s.LastStatus,
s.LastRunTime,
CONVERT(xml, s.ExtensionSettings) AS ExtensionSettings,
s.DeliveryExtension
FROM
dbo.Subscriptions s
INNER JOIN dbo.[Catalog] c ON c.ItemID = s.Report_OID
WHERE
s.LastStatus LIKE 'Failure%'
)
SELECT
[Name],
[Path],
[Description],
LastStatus,
LastRuntime,
CASE
WHEN DeliveryExtension = 'Report Server FileShare' THEN (SELECT e.c.value('(Value/text())[1]', 'nvarchar(max)') FROM ExtensionSettings.nodes('ParameterValues/ParameterValue') e(c) WHERE e.c.value('(Name/text())[1]', 'nvarchar(max)') = 'USERNAME')
WHEN DeliveryExtension = 'Report Server Email' THEN (SELECT e.c.value('(Value/text())[1]', 'nvarchar(max)') FROM ExtensionSettings.nodes('ParameterValues/ParameterValue') e(c) WHERE e.c.value('(Name/text())[1]', 'nvarchar(max)') = 'TO')
ELSE NULL
END AS Subscriber
FROM
SubscriptionsCTE
The problem is that the field Subscriber is encrypted for FileShare subscriptions. I understand that it is for the password... but for the user name? As an administrator I have access to the subscriptions via the GUI, but it is a pain to look into every report's admin panel to find out the user name.
I did something like
CASE WHEN Subscriber = '(some encrypted string)' THEN 'User 1'
WHEN Subscriber = '(some other encrypted string)' THEN 'User 2'
(etc.)
ELSE NULL
END AS Subscriber
But obviously, it is not encrypted in the same way in every record, so 'User 1' has a different encrypted string in every subscription.
Is there any way to decrypt these strings? I have the .snk file from the Report Server certificates backup (and know the password for it). Does this help?
Thanks for helping...
Best wishes
Michael

Remove permission from public

please see snap shoot below.I was wondering why I can't remove the permission with following code. But I can remove the permission by using the GUI.
REVOKE ALL ON OBJECT::[dbo].[Table1] FROM [PUBLIC];
It tested this on SQL Server 2005, and the query works fine. However, do not expect the table Properties dialog to update automatically, not even after moving forward and back to another page, like Storage. You must close and reopen the dialog to see the modifications.
I checked this by running the following script in steps:
Source: How to list permissions for Public Role for a database in SQL Server.
grant select, insert, update on dbo.Table1 to public
GO
SELECT a.[name] + ' ' + v.[name] + ' ON ' + QuoteName(oo.[name])
+ '.' + QuoteName(o.[name]) + ' TO ' + QuoteName(u.[name])
FROM dbo.sysprotects AS p
JOIN master.dbo.spt_values AS a
ON (a.number = p.protecttype
AND 'T' = a.type)
JOIN master.dbo.spt_values AS v
ON (v.number = p.action
AND 'T' = v.type)
JOIN dbo.sysobjects AS o
ON (o.id = p.id)
JOIN dbo.sysusers AS oo
ON (oo.uid = o.uid)
JOIN dbo.sysusers AS u
ON (u.uid = p.uid)
WHERE 'public' = u.name
GO
revoke all on object::dbo.Table1 to public
GO
-- Run query again
Please note that a warning is issued when using revoke all: The ALL permission is deprecated and maintained only for compatibility. It DOES NOT imply ALL permissions defined on the entity.

Copy table schema from DB2 to SQL Server

I'm looking at creating staging tables in SQL Server for one of our SSIS packages to reduce the number of calls to DB2 since calls to DB2 may experience timeouts when DB2 recycles inactive connections. Is there an automated method for copying table schema from DB2 to SQL Server? There would need to be a 1 to 1 mapping of data types between DB2 and SQL Server for this to work. If there isn't a tool that exists, I may write one myself since some of our DB2 tables have 20+ columns and it would be a pain to manually recreate in SQL Server.
I have a partially working script you're welcome to use. We don't care about primary keys and such from DB2 into our SQL Server side of things. Our only concern is to get the data over. Plus, the data I've had to deal with was only string or date based so where I build the data_type might be incorrect for the decimal.
The core concept is that I inspect the sysibm.syscolumns to derive a list of all the tables and columns and then try to provide a translation between the DB2 data types and SQL Server.
Anyways, give it a shot. Feel free to edit or make a comment about what's broken and I'll see if I can fix it.
This is built using a mix of the SQL Server 2012 CONCAT function and the classic string concatenation operator +. It also assumes a Linked server exists for the OPENQUERY to work.
WITH SRC AS
(
SELECT
OQ.NAME AS column_name
, OQ.TBNAME AS table_name
--, RTRIM(OQ.COLTYPE) AS data_type
, CASE RTRIM(OQ.COLTYPE)
WHEN 'INTEGER' THEN 'int'
WHEN 'SMALLINT' THEN 'smallint'
WHEN 'FLOAT' THEN 'float'
WHEN 'CHAR' THEN CONCAT('char', '(', OQ.LENGTH, ')')
WHEN 'VARCHAR' THEN CONCAT('varchar', '(', OQ.LENGTH, ')')
WHEN 'LONGVAR' THEN CONCAT('varchar', '(', OQ.LENGTH, ')')
WHEN 'DECIMAL' THEN CONCAT('decimal', '(', OQ.SCALE, ')')
WHEN 'DATE' THEN 'date'
WHEN 'TIME' THEN 'time'
WHEN 'TIMESTMP' THEN ''
WHEN 'TIMESTZ' THEN ''
WHEN 'BLOB' THEN ''
WHEN 'CLOB' THEN ''
WHEN 'DBCLOB' THEN ''
WHEN 'ROWID' THEN ''
WHEN 'DISTINCT' THEN ''
WHEN 'XML' THEN ''
WHEN 'BIGINT' THEN ''
WHEN 'BINARY' THEN ''
WHEN 'VARBIN' THEN ''
WHEN 'DECFLOAT' THEN ''
ELSE ''
END AS data_type
, OQ.LENGTH
, OQ.SCALE
, CONCAT(CASE OQ.NULLS WHEN 'Y' THEN 'NOT' ELSE '' END, ' NULL') AS allows_nulls
, OQ.UPDATES AS updateable
FROM
OPENQUERY(LINKED, 'SELECT * FROM abcde01.sysibm.syscolumns T WHERE T.TBCREATOR = ''ABCD'' ' ) AS OQ
)
, S2 AS
(
SELECT
CONCAT(QUOTENAME(S.column_name), ' ', S.data_type, ' ', S.allows_nulls) AS ColumnDeclaration
, S.table_name
FROM
SRC AS S
)
, MakeItPretty AS
(
SELECT DISTINCT
QUOTENAME(S.TABLE_NAME) AS TABLE_NAME
, STUFF
(
(
SELECT ',' + ColumnDeclaration
FROM S2 AS SI
WHERE
SI.TABLE_NAME = S.TABLE_NAME
FOR XML PATH('')),1,1,''
) AS column_list
FROM
S2 AS S
)
SELECT
CONCAT('CREATE TABLE ', MP.TABLE_NAME, char(13), MP.column_list) AS TableScript
FROM
MakeItPretty AS MP;

Resources