Message 102, wrong syntax near '>' - tsql

I wanted to evaluate a simple iif-statement on Transact SQL, but the debugger always returns the message, there's an error near '>'. So I also tried one of the examples, given in the MSDN, but that failed either.
These are the statements I want to evaluate separately. The second one is from the MSDN and it fails, too.
select #land + iif(len(isnull(#land, '')) > 0
and len(isnull(#plz, '')) > 0, ' - ', '')
+ #plz
SELECT IIF ( 45 > 30, NULL, NULL ) AS Result;
And this is my environment
Microsoft SQL Server Management Studio 10.50.1600.1
Microsoft Data Access Components (MDAC) 6.1.7601.17514
Microsoft MSXML 3.0 4.0 5.0 6.0
Microsoft Internet Explorer 9.0.8112.16421
Microsoft .NET Framework 2.0.50727.5420
Operating System 6.1.7601 (Windows 7)

IIF is a new feature of SQL Server 2012 - you cannot use it in 2008 R2.....
This page lists all the new Programmability features of SQL Server 2012 - you'll find IIF under 14 New Functions..... a bit past the middle of the page.

Related

"A mismatch between the PNP/INF version and the KMD file version on the graphics adapter has been detected"

I've been testing a UMDF IddCx video driver, and this message just started appearing (after devcon.exe install ...) along with a breakpoint in WinDbg:
(DriverEntry and EVT_WDF_DRIVER_DEVICE_ADD handlers succeed as they did prior to this error message)
.
.
.
<==CDriver::OnWdfDriverDeviceAdd [status: STATUS_SUCCESS]
A mismatch between the PNP/INF version and the KMD file version on the graphics adapter has been detected. The adapter will fail to start.
(WinDbg breaks here -- see stack below)
==>CAdapter::OnWdfDeviceD0Entry(hWdfDevice: <hWdfAdapterDevice>, previousState: 5)
.
.
.
Stack info (Windows 10 Pro | Test Mode | Build 19041.vb_release.191206-1406):
[0x0] dxgkrnl!DpiFdoValidateKmdAndPnpVersionMatch + 0x88e5c
[0x1] dxgkrnl!DpiFdoInitializeFdo + 0x313
[0x2] dxgkrnl!DpiAddDevice + 0x1942
[0x3] nt!PpvUtilCallAddDevice + 0x3b
[0x4] nt!PnpCallAddDevice + 0x94
[0x5] nt!PipCallDriverAddDevice + 0x827
[0x6] nt!PipProcessDevNodeTree + 0x333
[0x7] nt!PiRestartDevice + 0xba
[0x8] nt!PnpDeviceActionWorker + 0x46a
[0x9] nt!ExpWorkerThread + 0x105
[0xa] nt!PspSystemThreadStartup + 0x55
[0xb] nt!KiStartSystemThread + 0x28
I don't understand what this means; I haven't changed anything in the INF, and this is a UMDF driver, so what "KMD file version" is it referring to? I searched for the message itself and also DpiFdoValidateKmdAndPnpVersionMatch, but came up empty.
EDIT: (adding version info)
Windows Version Info:
---------------------
Edition ....... Windows 10 Pro
Version ....... 20H2
Installed on .. 1/5/2021
OS build ...... 19042.685
Experience .... Windows Feature Experience Pack 120.2212.551.0
Can anyone shed light on this?
the Symbol Doesn't Exist in 1909 so that symbol must be a new addition to 20H2
anyway the string in question does exist in 1909
the Failure is supposedly propagated after IoQueryFullDriverPath() and GetFileVersion()
the int3 is Hardcoded after the DebugPrintEx()
the function in question ADAPTER_RENDER::Initialize() is doing a lot of comparisons with hardcoded DWORDS like 'QCOM' etc
C:\> radare2 -Q -qq -c "fs strings;f~mismatch" c:\Windows\System32\drivers\dxgkrnl.sys
0x1c0076940 139 str.A_mismatch_between_the_PNP_INF_version_and_the_KMD_file_version_on_the_graphics_adapter_has_been_detected._The_adapter_will_fail_to_start.
C:\> radare2 -A -Q -qq -c "axt 0x1c0076940" c:\Windows\System32\drivers\dxgkrnl.sys
fcn.1c015be84 0x1c0181f01 [DATA] lea r8, str.A_mismatch_between_the_PNP_INF_version_and_the_KMD_file_version_on_the_graphics_adapter_has_been_detected._The_adapter_will_fail_to_start.
i was just googling around look for something related to inf and GetKmdFileVersion and it seems you need to provide a specific Version String
see if you comply with this
specifically quoting from the doc
Drivers will report WDDM 2.1 support through
DXGK_DRIVERCAPS::WDDMVersion with a new version constant:
DXGK_WDDMVERSION::DXGKDDI_WDDMv2_1 = 0x2100 Dxgkrnl will not use the
WDDMVersion cap as a way to determine which new features are
supported—that task will be left to other caps or DDI presence.
However, if the driver reports WDDM 2.1 support through the
WDDMVersion cap, dxgkrnl will validate that caps or DDIs required by
WDDM 2.1 are present and fail to create the adapter if they are not.
Inconsistent caps will result in failure to create adapter or segment.
Please try adding the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\DisableVersionMismatchCheck = 1 [DWORD Type]

Detecting error after a powershell statement is executed

I am using powershell to run sqlplus and I would like PowerShell to detect if there are error after the script was run and to perform some action instead of me looking at the result file.
& 'sqlplus' 'system/myOraclePassword' '#Test' | out-file 'result.txt';
Normally in DOS, there is %errorlevel% when the command encounters error and I wonder if there is similar stuff in PowerShell?
Of course, I can read the log file myself but sometimes, thing got too routine and I may forget.
My Test.sql:
select level from dual
connect by level<5;
select 10/0 from dual;
quit;
There is clearly a division by zero error. The result.txt captures it but I would like powershell to detect it as well
SQL*Plus: Release 12.1.0.2.0 Production on Thu Apr 27 16:24:30 2017
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Last Successful login time: Thu Apr 27 2017 16:17:34 -04:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
LEVEL
----------
1
2
3
4
select 10/0 from dual
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
Does the powershell statement return an errorlevel after the statement is executed like DOS?
I have tried:
& 'sqlplus' 'system/myOraclePassword' '#Test' | out-file 'result.txt';
if (errorlevel 1)
{ write-host error;
}
else
{ write-host ok;
}
But that has caused syntax error?
errorlevel : The term 'errorlevel' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and
try again.
What is a proper way to check error in powershell?
UPDATE
I used this:
if ($LASTEXITCODE -ne 0 )
{
write-host error;
}
else
{
write-host ok;
}
Since you are invoking an executable, you probably want to check for the $LASTEXITCODE variable or the return value of sqlplus. In PowerShell each variable has a $ prefix.

SQL Server: Cannot find data type date and unable to set compatibility

I have a install script that uses DATE. I'm running SQL Server 2008 R2, and it doesn't like the date type.
Msg 2715, Level 16, State 7, Line 1
Column, parameter, or variable #3: Cannot find data type date.
So I tried setting the compatibility of the database to 100 using the following:
ALTER DATABASE znode_multifront SET COMPATIBILITY = 100
I receive the following error:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '100'.
So I tried going into SQLCMD mode and used the following:
EXEC sp_dbcmptlevel znode_multifront, 100;
Which produced the following error:
Msg 15416, Level 16, State 1, Procedure sp_dbcmptlevel, Line 70
Usage: sp_dbcmptlevel [dbname [, compatibilitylevel]]
I am very new to SQL Server. Any help would be greatly appreciated.
alter database znode_multifront
set compatibility_level = 100
go
You were close. The set option is COMPATIBILITY_LEVEL, not COMPATIBILITY like you have in your original post.
You will need ALTER permission on the database to execute the above query.

Inconsistent cursor results when looping over databases

I have several databases named very similar (my-db-1, my-db-2, my-db-3, my-db-4). I want to execute the same stored procedure on each of these databases. I decided to use cursors. However, I am getting some strange issues. First here is my simple code that I am executing through SQL Server Management Studio 2008.
DECLARE #db_cursor CURSOR
DECLARE #name varchar(255)
DECLARE #Sql nvarchar(4000)
SET #db_cursor = CURSOR FOR
SELECT name FROM sys.databases WHERE name LIKE 'my-db-%'
OPEN #db_cursor
FETCH NEXT FROM #db_cursor INTO #name
WHILE ##FETCH_STATUS = 0
BEGIN
SET #Sql = 'Use [' + #name + ']; PRINT DB_NAME();'
exec sp_sqlexec #Sql
FETCH NEXT FROM #db_cursor INTO #name
END
CLOSE #db_cursor
DEALLOCATE #db_cursor
Executing this multiple times in a row within 2 seconds, I get strange results:
Execution1:
my-db-1
my-db-2
my-db-3
my-db-4
Execution2:
my-db-1
my-db-2
Execution3:
my-db-1
my-db-2
my-db-3
my-db-4
Execution4:
my-db-1
It seems like its completely random. Sometimes I'll get all 4 databases to print after 10 executions. Sometimes after just 2 executions only 1 database will get printed.
This SQL is executing on Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64) Apr 2 2010 15:48:46 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.1 (Build 7600: ) through Microsoft SQL Server Management Studio 10.50.1600.1
Does anyone have any ideas?
Try declaring your cursor as FAST_FORWARD.
The default is an updateable cursor and these required update locks probably conflict with another process accessing sys.databases
Ref.: DECLARE CURSOR

How to programatically compare permissions of login/user in SQL Server 2005

There's a login/user in SQL Server who is having a problem importing accounts in production server. I don't have an idea what method he is doing this. According to the one importing, this import is working fine in development server. But when he did the same import in production it is giving him errors. Below are the errors he is getting for each accounts.
2009-06-05 18:01:05.8254 ERROR [engine-1038] Task [1038:00001 - Members]: Step 1.0 [<Insert step description>]: Task.RunStep(): StoreRow has failed
2009-06-05 18:01:05.9035 ERROR [engine-1038] Task [1038:00001 - Members]: Step 1.0 [<Insert step description>]: Task.RunStep(): StoreRow exception: Exception caught while storing Data. [Microsoft][ODBC SQL Server Driver][SQL Server]'ACCOUNT1' is not a valid login or you do not have permission.
Please note that 'ACCOUNT1' is not the real account name. I just changed it for security reason.
Using SQL Server Management Studio (SSMS), I viewed/checked the permissions of the user/login who is performing the import from development server and production for comparison. I found no difference.
My question is: Is there a way to programmatically query permissions in server and database level of a particular login/user so I can compare/contrast for any differences?
Red Gate's SQL Compare wil do it for you.
This code shows all the rights that the login has.
select sys.schemas.name 'Schema', sys.objects.name Object, sys.database_principals.name username, sys.database_permissions.type permissions_type,
sys.database_permissions.permission_name,
sys.database_permissions.state permission_state,
sys.database_permissions.state_desc,
state_desc + ' ' + permission_name + ' on ['+ sys.schemas.name + '].[' + sys.objects.name + '] to [' + sys.database_principals.name + ']' COLLATE LATIN1_General_CI_AS
from sys.database_permissions
join sys.objects on sys.database_permissions.major_id =
sys.objects.object_id
join sys.schemas on sys.objects.schema_id = sys.schemas.schema_id
join sys.database_principals on sys.database_permissions.grantee_principal_id =
sys.database_principals.principal_id
order by 1, 2, 3, 5
You should be able to use
sp_helplogins '<loginname>'
See the MSDN reference here.