My SCCM 2007 SQL Web Report is not displaying results - sql

I created an SCCM SQL report using SQL Management Studio. I then created the following prompts for my Asset Management Office to use on the web report: Publisher, Display Name, and Version.
The Display Name and the Version prompts are both optional.
I receive no syntax errors or anything, but I receive absolutely no results whatsoever when I click on the Display button to produce the web report.
Here is my SQL code:
==================================================================================
SELECT dbo.v_R_System.Netbios_Name0, dbo.v_GS_ADD_REMOVE_PROGRAMS.DisplayName0, dbo.v_GS_ADD_REMOVE_PROGRAMS.Version0,
dbo.v_GS_ADD_REMOVE_PROGRAMS.Publisher0
FROM dbo.v_R_System INNER JOIN
dbo.v_GS_ADD_REMOVE_PROGRAMS ON dbo.v_R_System.ResourceID = dbo.v_GS_ADD_REMOVE_PROGRAMS.ResourceID
WHERE dbo.v_GS_ADD_REMOVE_PROGRAMS.DisplayName0 = #DisplayName AND dbo.v_GS_ADD_REMOVE_PROGRAMS.Version0 = #Version AND dbo.v_GS_ADD_REMOVE_PROGRAMS.Publisher0 = #Publisher
Order by dbo.v_GS_ADD_REMOVE_PROGRAMS.DisplayName0 ASC
==================================================================================
I run my report and in the Publisher prompt, I type in something like %Autodesk% and then I click the Display button, and absolutely nothing is displayed. I can go to another report and look up Autodesk products, but not this one. I am not a well versed SQL guy, so if anyone can help me that would be great.
Thanks

% signs often mean wildcards. They are used with the like keyword. You have equal signs. In other words,
where DisplayName like '%fred%'
will return fred, freddie, frederick, etc. However,
where DisplayName = '%fred%'
will only return %fred%

AHHHH I see what you were talking about Dan.
Disregard my last statement/inquiry everyone, I got my code working now. My Prompt #variables' SQL code was not configured properly to work with the "Like" constant so I modified my main SQL code to be this:
==================================================================================
Select Distinct dbo.v_R_System.Netbios_Name0, dbo.v_GS_ADD_REMOVE_PROGRAMS.DisplayName0, dbo.v_GS_ADD_REMOVE_PROGRAMS.Version0, dbo.v_GS_ADD_REMOVE_PROGRAMS.Publisher0
FROM dbo.v_R_System
Join dbo.v_GS_ADD_REMOVE_PROGRAMS On dbo.v_R_System.ResourceID = dbo.v_GS_ADD_REMOVE_PROGRAMS.ResourceID
Where dbo.v_GS_ADD_REMOVE_PROGRAMS.Publisher0 Like #Publisher Or dbo.v_GS_ADD_REMOVE_PROGRAMS.DisplayName0 Like #DisplayName Or dbo.v_GS_ADD_REMOVE_PROGRAMS.Version0 Like #VersionOrder by dbo.v_GS_ADD_REMOVE_PROGRAMS.DisplayName0 ASC
==================================================================================
Then I had to modify my Prompt SQL code to use the Begin, If, Else, and End statements. I will pick just my #Publisher variable Prompt SQL code since all of my Prompt #variables' SQL code are basically identical.
Here is the SQL code for my Publisher (#Publisher) Prompt:
==================================================================================
Begin
If(#__filterwildcard = '')
Select Distinct Publisher0
From v_Add_Remove_Programs Order By Publisher0
Else
Select Distinct Publisher0
From v_Add_Remove_Programs
Where Publisher0 Like #__filterwildcard
Order By Publisher0
End
==================================================================================
The code I used before for my Prompt #variables was like this which did not work with the "Like" constant in my main SQL code:
==================================================================================
Select Distinct Publisher0
From v_Add_Remove_Programs Order By Publisher0
Where Publisher0 Like #__filterwildcard
Order By Publisher0
==================================================================================
So, apparently using the Begin, If, Else, and End statements allowed for more logic in this query process, therefore allowing me to use the "Like" constant in my main SQL code for the report.

Related

SQL Sub-query parameters from Excel

I have SQL query with a sub-query where I want to assign sub query parameters from a cell in an Excel sheet, as this query cant be represented graphically Excel keep throwing error on this:
[Microsoft][ODBC SQL Server Driver] Invalid paramter number and
[Microsoft][ODBC SQL Server Driver] Invalid Descriptor Index
I have already tried solution as mentioned here to trick excel without success Using Parameters in SQL query with sub-query
;WITH dataset_bl as (
SELECT
--rank() over (partition by date_of_AC, ac_room order by into_theatre) as OrderNumber
--,datetime_of_AC as booking_datetime
date_of_AC
,AC_room
,specialty
,OAMRN
,substring(Subject_NAME,1,CHARINDEX(' ',Subject_NAME,1)) as 'surname'
,substring(Subject_NAME,CHARINDEX(' ',Subject_NAME,1)+2,500) as 'forename'
,convert(date,[dttm_of_birth],103) as DOB
,PRIN_SO as 'surg'
,'"'+ASST_SO_1+' '+ASST_SO_2+'"' as 'assistant_SO'
,substring(CONSULT_NAME,1,abs(CHARINDEX(',',CONSULT_NAME,1)-1)) as 'consult_surname'
,substring(CONSULT_NAME,CHARINDEX(' ',CONSULT_NAME,1)+1,500) as 'consult_first_name'
,'"'+actual_AC+'"' as AC_details
,'"'+PLANNED_PROD+'"' as booked_details
,'Carried Out' as 'TT_outcome'
, 'NULL' as 'unP_return_flag'
,OP_type
--,LOS
,case when CL_PRIORITY ='' then 'Not listed' else 'isted' end as islisted
,CLI_PRIORITY as listed_priority
,case when EM_PRIORITY like '<=%' then 'Submitted' else 'No Greensheet' end as isGreensheet
,em_priority as a, case when EM_PRIORITY like '<=%' and em_priority <> '<=72hrsCannot charge before prod'then LEFT(EM_PRIORITY, abs(charindex('-',EM_PRIORITY)-1))
when em_priority = '<=72hrsCannot diso before prod' then '<=72hrs' else 'NULL' end as em_priority
FROM sample.dbo.tb_Fnl_Sur_th4 WITH (NOLOCK)
**WHERE main_ident = 'A224' and convert(date,into_Start, 103) >= '2019-07-01' and convert(date,into_Start, 103) <= '2019-07-31'** --i am trying to get these parameters from excel cell value
)
SELECT * FROM dataset_bl
WHERE specialty like 'abc%'
or (consult_surname like '%abc%' and consult_first_name like '%def%' )
or surg in ('cde,fghi',
'jkl,'mnop,
'qrs,Tuv')
order by convert(date,date_of_procedure,103), operating_room--, into_theatre
Here's some suggestion.
First is to check the formatting of your date columns.
and build your parameter to be like
Cast(into_Start as smalldatetime) between ? and ?
I've been on that same issue and seem to find the solution for me. In fact the parameter [?] use in MSQUERY in Excel will normally work when you have a direct Query
Ex:
Select [YourTable].[Column]
From [YourTable]
Where [YourTable].[Column]= ?
The Excel parameter will prompt and trigger where the windows that ask you which cell or Data you want that parameter have to be filled with.
In the other hand if you use the a Subquery and you add a Where condition with the Parameter ? will be stuck with the parameter [Microsoft][ODBC SQL Server Driver] Invalid paramter number and [Microsoft][ODBC SQL Server Driver] Invalid Descriptor Index
If you download the ODBC Driver for SQL Server here -->
https://www.microsoft.com/fr-fr/download/details.aspx?id=56567
Install it and make sure that the ODBC use for your MSQUERY in Excel use that connection.
ODBC Data Source to use
After this I was able to use a MSQuery in Excel using Parameter like this one
Select [RenamedTable].*
From (Select [YourTable].[Column1],
[YourTable].[Column2],
[YourTable].[Column3]
From [YourTable]) as RenamedTable
Where [RenamedTable].[Column1] between ? and ?
Hope this will work for you as for me because I had similar problem with between date Parameter

What does this DDL Audit example provide

Can someone explain this code line by line? I would like to understand the purpose and effect of each line this code has. This code is from Microsoft and doesn't have the best description of what is going on. I plan to use this code and would like to know where the generic names are as well vs the syntactically correct code. THANKS!!
From Microsoft, looked at their documentation but can't find everything
enter code here
USE DATABASE;
GO
SELECT *
FROM fn_trace_gettable
(drive, default);
GO
SELECT
TE.name AS [DLL_EDIT],
TT.DatabaseName,
TT.DatabaseID,
TT.ApplicationName,
TT.LoginName,
TT.Duration,
TT.Duration,
TT.StartTime,
TT.EndTime
FROM sys.fn_trace_gettable(
CONVERT (VARCHAR(4000),
(
SELECT TOP 1
f.[value]
FROM sys.fn_trace_gettable(NULL) f
WHERE f.property = 2
)), DEFAULT
) TT
JOIN
sys.trace_events TE
ON TT.EventsClass = TE.trace_events_id
ORDER BY TT.StartTime desc;
))
)

T-SQL capturing Linked server name as a result column

How can I capture the (linked) server (in this case Morpheus) name as a column of the result. I do not want to define the Server name in the query itself.
exec("
select
COMNO
,T$CPLS ""Catalog""
,T$CUNO ""Customer ID.""
,T$CPGS ""Price Group""
,T$ITEM ""Item Code""
,T$UPCD UPC
,T$DSCA ""Description""
,T$WGHT ""Weight""
,T$SHIP ""Shipping Indicator""
,nvl(T$STDT,to_char(sysdate,'YYYY-MM-DD')) ""From""
,nvl(case T$TDAT
when '4712-01-01' then ' '
when null then ' '
else t$tdat
end,' ') ""To""
,nvl(t$qanp,99999999) ""Qty.""
,T$PRIC ""List Price""
,T$DISC ""Discount""
,to_char(round(t$pric * (1-t$disc/100),2),99999.99) ""Net""
,Source ""Source""
from Table(edi.ftCompositCatalog(?,?,?)) --where trim(t$item)='105188-041'
order by Source,t$cpgs,t$item",'010','145','000164') at morpheus
If, when running your query, you already know what linked server you are pointing to, then just include that as a string literal in your result:
exec("
select
'morpheus' ""Server Name""
,T$CPLS ""CATALOG""
...
Even if the linked server name is being stored in a variable, you can do this easily since you're building your query string dynamically.
If, as you say, you don't want to define it as a string literal, here is a normal way to get the host (server) name in Oracle:
SELECT SYS_CONTEXT ('USERENV', 'SERVER_HOST') FROM DUAL;
If you want to embed this as a subquery or inline view in your query, I think it would work.
*Please note that some organizations & dba's do not want you to know anything about the backend environment for security reasons, but assuming you have no roadblock there, this should work.

Oracle ADF View Object Expert Mode setWhereClause can't execute parameter from wrapped query

I have a query which is expert mode query. Also I have viewCriteria and whereClause.
When I use whereClause like under and execute; viewObject can't take any row from database. But when I put the same query in toad, i can see the result. Can you help me...
viewObject getQuery result
SELECT *
FROM (SELECT CO.CUST_ORD_ID,
PA.ACTORID_ AS WRK_GRP_ID,
CO.CUST_ID,
cam_pkg.getCustomerFullName (CO.CUST_ID) AS CUST_NAME,
WG.NAME AS WRK_GRP_NAME,
TI.CREATE_ AS ACTOIN_DATE,
WT.WFLW_TASK_ID,
WT.NAME AS WFLW_TASK_NAME,
TI.NAME_ AS TASK_SHRT_CODE,
CO.ORD_ST_ID,
ORS.NAME AS ORD_ST_NAME,
TI.PROCINST_ AS PROC_INSC_ID,
TI.ID_ AS TASK_ID
FROM cust_ord co,
JBPM_TASKINSTANCE TI,
jbpm_pooledactor PA,
jbpm_taskactorpool TAP,
wrk_grp WG,
ord_st ORS,
WFLW_TASK wt
WHERE CO.CUST_ORD_ID =
jbpm_pkg.get_subLong_jbpm_var_insc (TI.PROCINST_,
'CustOrderId')
AND TI.ISOPEN_ = 1
AND TI.END_ IS NULL) QRSLT
WHERE (TASK_ID IN
(1128732,
1129513))
which version of jdeveloper? and how exactly are you applying the view criteria? Are you sure you query is getting formed as you are expecting? Try to enable logging by putting
-Djbo.debugoutput=console in the run/debug properties of your view control project (make sure to bounce the server)

DISTINCT is not working

SQL query in Ms-Access
INSERT INTO tblTmpEventLog( TrackingNumber, PartNumber, PartNumberChgLvl,
EnteredBy, EventTypeSelected, EventDate )
SELECT DISTINCT tblRevRelLog_Detail.RevRelTrackingNumber,
tblRevRelLog_Detail.PartNumber, tblRevRelLog_Detail.ChangeLevel,
[Forms]![frmEventLog_Input]![EnteredBy] AS EnteredBy,
[Forms]![frmEventLog_Input]![EventTypeSelected] AS EventTypeSelected,
CDate([Forms]![frmEventLog_Input]![EventDate]) AS EventDate
FROM tblRevRelLog_Detail LEFT JOIN tblEventLog
ON (tblEventLog.PartNumber = tblRevRelLog_Detail.PartNumber)
AND (tblEventLog.PartNumberChgLvl = tblRevRelLog_Detail.ChangeLevel)
WHERE ((([tblRevRelLog_Detail]![RevRelTrackingNumber]) =
[Forms]![frmEventLog_Input]![TrackingNumber]))
AND ((tblEventLog.PartNumber) NOT IN
(SELECT tblEventLog.PartNumber FROM tblEventLog
WHERE tblEventLog.EventTypeSelected = 'pn REMOVED From Wrapper'
AND tblEventLog.TrackingNumber =
tblRevRelLog_Detail.RevRelTrackingNumber
AND tblEventLog.PartNumber = tblRevRelLog_Detail.PartNumber
AND tblEventLog.PartNumberChgLvl =
tblRevRelLog_Detail.ChangeLevel
));
DISTINCT keyword for EnteredBy, EventTypeSelected is not working..I mean, data for these columns is not displaying when I use DISTINCT keyword.
EVENTDATE is working fine, but I do not understand why is it not displaying for EneteredBy and EventTypeSelected columns.
Can anyone tell me how to handle this?
It may be that the query can't interpret properly from the form directly as the final data type. However in your date field, you are wrapping it in a function CDATE( ... ). So, the SQL engine knows the result type. I would suggest doing the same for the other fields. Ex: doing a CAST ( ...your form control... as DateTime ) as OtherColumn, etc... I THINK Access allows casting, but not positive. Otherwise, pre-pull the form value into a declared data type variable and use THAT variable in the query AS OtherColumn as you are doing.
Additionally to what #Jack mentioned, you can always go back to your account, look at your historical question, and click on whatever answers actually helped / solve your problems. Some questions never do get answers and that's ok, just give credit to those that DO help.
I have found in the past (I don't remember which old version of Access this was) that if you set the value of a form control in VBA, and then use that control in a query, the query will not see the value you set in VBA. If the user edits the control normally, the query sees the expected value. Perhaps that's what happened here.
To work around that, you can declare a VBA function that returns the desired value. For example, instead of this:
SELECT ..., Forms!MainForm!TextEntry AS TextEntry, ... FROM ...
use this:
SELECT ..., GetTextEntry() AS TextEntry, ... FROM ...
along with this:
Public Function TextEntry() As Variant
TextEntry = Forms!MainForm!TextEntry
End Function