2 Replies - 1351 Views - Last Post: 09 January 2014 - 05:28 PM Rate Topic: -----

#1 lewcianci  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-May 12

Parameters aren't working in SQL query

Posted 08 January 2014 - 06:32 PM

Hi all,

Been googling my little heart out all morning, can't figure this out.

Basically, I've got a checkboxlist on my web page, and when i tick certain boxes, i want it to change a sql parameter so the select query changes (and so I get new results).

The SQL Query is

SELECT [soe_version], [hostname], [siteid] FROM [tbl_SOECompliancy919] WHERE ID IN (SELECT MAX(ID) FROM TBL_SOECOMPLIANCY919 GROUP BY HOSTNAME) AND SITEID IN('Sites go here') 


I have tried to change this parameter by way of changing the selectparameters on page load, but still no joy. I think the main reason for this is because when the input goes in as a parameter, it gets sanitized, so SQL Server will treat the parameter input as one variable (So something like ('Floor1,Floor2,Floor3' when what I want its ('Floor1','Floor2','Floor3').

I've tested this query in the SQL IDE (Forget what its called) and its worked.

SELECT [soe_version], [hostname], [siteid] FROM [tbl_SOECompliancy919] WHERE ID IN (SELECT MAX(ID) FROM TBL_SOECOMPLIANCY919 GROUP BY HOSTNAME) AND SITEID IN('Floor1','Floor2','Floor3') 


Not sure how to proceed... any help would be awesome :)

Is This A Good Question/Topic? 0
  • +

Replies To: Parameters aren't working in SQL query

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: Parameters aren't working in SQL query

Posted 09 January 2014 - 12:27 PM

You can simply format string. All you need to do is change the , to ','.
Was This Post Helpful? 0
  • +
  • -

#3 lewcianci  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-May 12

Re: Parameters aren't working in SQL query

Posted 09 January 2014 - 05:28 PM

View Postlucky3, on 09 January 2014 - 12:27 PM, said:

You can simply format string. All you need to do is change the , to ','.


Okay... Heres how I understand variables and parameters in SQL.

If my input is WHERE IN ('floor1','floor2','floor3'), and I want to parameterize that, if I just set @SiteID to 'floor1','floor2','floor3') and call WHERE IN (@SiteID), then the way it will get passed will be like:

''floor1','floor2','floor3''

What I mean by that is that the parameter will get parsed literally, so sql won't see the delimeters and think oh hey, theres more than one variable here.

Does that make any sense? Sorry if it doesn't :(
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1