Question

I need some help writing an SQL query and I am not well versed in this by any means. I am trying to find computer hardware on systems that have software installed with a display name of, lets just say, "TestMe". Here is the SQL code:

SELECT dbo.v_GS_ADD_REMOVE_PROGRAMS_DispalyName0, SYS.Netbios_Name0, Processor.Name0, Processor.MaxClockSpeed0, Processor.DeviceID0
FROM v_R_System SYS
JOIN v_GS_PROCESSOR Processor on SYS.ResourceID=Processor.ResourceID
JOIN dbo.v_GS_ADD_REMOVE_PROGRAMS
WHERE v_GS_ADD_REMOVE_PROGRAMS_DisplayName0 LIKE %TestMe%
ORDER BY SYS.Netbios_Name0

When I execute this, I keep getting the following error:

Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'WHERE'.

I greatly appreciate your help. Thanks everyone.

Was it helpful?

Solution 3

Sorry fellas I have not responded sooner, I've been very busy with family matters. Anyway, I decided against the SQL report and just went with a WMI query instead that seemed to provide the results that I was looking for because the SQL report was only to target systems that have a specific piece of software installed and I dont want to use my SQL reporting for that since it is just for temporary usage. That's why I went with the WMI query. Here is the WMI query code I used:

select distinct SMS_R_System.Name, SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName, SMS_G_System_ADD_REMOVE_PROGRAMS.Version, SMS_G_System_X86_PC_MEMORY.TotalPhysicalMemory, SMS_G_System_LOGICAL_DISK.Size, SMS_G_System_IDE_CONTROLLER.Description, SMS_G_System_PROCESSOR.Name, SMS_G_System_PROCESSOR.MaxClockSpeed, SMS_G_System_PROCESSOR.AddressWidth, SMS_G_System_MOTHERBOARD_DEVICE.PrimaryBusType, SMS_G_System_VIDEO_CONTROLLER.VideoProcessor, SMS_G_System_VIDEO_CONTROLLER.AdapterRAM, SMS_G_System_OPERATING_SYSTEM.Caption, SMS_G_System_OPERATING_SYSTEM.CSDVersion from  SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_X86_PC_MEMORY on SMS_G_System_X86_PC_MEMORY.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_PROCESSOR on SMS_G_System_PROCESSOR.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_VIDEO_CONTROLLER on SMS_G_System_VIDEO_CONTROLLER.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_MOTHERBOARD_DEVICE on SMS_G_System_MOTHERBOARD_DEVICE.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_IDE_CONTROLLER on SMS_G_System_IDE_CONTROLLER.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_LOGICAL_DISK on SMS_G_System_LOGICAL_DISK.ResourceID = SMS_R_System.ResourceId where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName = "Varian Aria Radiation Oncology Client" order by SMS_R_System.Name

OTHER TIPS

you need on and the condition before the WHERE and also to put '%TestMe%' someting like this:

SELECT dbo.v_GS_ADD_REMOVE_PROGRAMS_DispalyName0, SYS.Netbios_Name0, Processor.Name0, Processor.MaxClockSpeed0, Processor.DeviceID0
FROM v_R_System SYS JOIN v_GS_PROCESSOR Processor on SYS.ResourceID=Processor.ResourceID JOIN dbo.v_GS_ADD_REMOVE_PROGRAMS as t on t.Id = SYS.ResourceID
WHERE v_GS_ADD_REMOVE_PROGRAMS_DisplayName0 LIKE '%TestMe%' ORDER BY SYS.Netbios_Name0

Please notice that I do not know the relation between your tables so t.Id = SYS.ResourceID needs to be change to the correct logical expresion.

you need single quotes ' around %TestMe% because you are using like operator.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top