CF Declaring SQL variables
Hi all, I've a section of query I'm trying to run, I've tried lots of different ways to write it but have had no success yet Does anyone know how this query should be written: [code] cfquery name=breadcrumb datasource=#REQUEST.theDatabase# !---SELECT the values for the Deleted level into variables--- DECLARE DeletedAreaName VARCHAR(50); DECLARE DeletedLft INTEGER; DECLARE DeletedRgt INTEGER; SELECT SiteAreaName, Lft, Rgt INTO DeletedAreaName, DeletedLft, DeletedRgt FROM directoryLinks WHERE SiteAreaName = '#ARGUMENTS.SiteAreaName#' /cfquery [/code] Thanks, Richard ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:244615 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: CF Declaring SQL variables
without testing: I think the into only takes the name of the (new) table If you need to change the column names you could try it like this: SELECT SiteAreaName as DeletedAreaName, Lft as DeletedLft , Rgt as DeletedRgt INTO DeletedArea FROM directoryLinks WHERE SiteAreaName = '#ARGUMENTS.SiteAreaName#' - Original Message - From: Richard Cooper [EMAIL PROTECTED] To: CF-Talk cf-talk@houseoffusion.com Sent: Friday, June 23, 2006 12:39 PM Subject: CF Declaring SQL variables Hi all, I've a section of query I'm trying to run, I've tried lots of different ways to write it but have had no success yet Does anyone know how this query should be written: [code] cfquery name=breadcrumb datasource=#REQUEST.theDatabase# !---SELECT the values for the Deleted level into variables--- DECLARE DeletedAreaName VARCHAR(50); DECLARE DeletedLft INTEGER; DECLARE DeletedRgt INTEGER; SELECT SiteAreaName, Lft, Rgt INTO DeletedAreaName, DeletedLft, DeletedRgt FROM directoryLinks WHERE SiteAreaName = '#ARGUMENTS.SiteAreaName#' /cfquery [/code] Thanks, Richard ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:244616 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: CF Declaring SQL variables
It's not strictly that I need to change the column names... I was planning to use them within the same query like this: [code] cfquery name=breadcrumb datasource=#REQUEST.theDatabase# !---SELECT the values for the Deleted level into variables--- DECLARE DeletedAreaName VARCHAR(50); DECLARE DeletedLft INTEGER; DECLARE DeletedRgt INTEGER; SELECT SiteAreaName, Lft, Rgt INTO DeletedAreaName, DeletedLft, DeletedRgt FROM directoryLinks WHERE SiteAreaName = '#ARGUMENTS.SiteAreaName#'; !---Perform the deletion--- DELETE FROM directoryLinks WHERE Lft BETWEEN DeletedLft AND DeletedRgt; !---UPDATE the table so that the gaps between Lft and Rgt values are removed--- UPDATE directoryLinks SET Lft = CASE WHEN Lft DeletedLft THEN Lft - (DeletedRgt - DeletedLft + 1) ELSE Lft END, Rgt = CASE WHEN Rgt DeletedLft THEN Rgt - (DeletedRgt - DeletedLft + 1) ELSE Rgt END WHERE Lft DeletedLft OR Rgt DeletedLft; /cfquery [/code] NB. Forgot to previously mention thatI'm using MX 7 SQL server 2000 ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:244618 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: CF Declaring SQL variables
Assuming you're using MS-SQL (not sure about other DBs), and assuming you're only trying to 'get' the data into the variables: Your variable should start with an '@'. DECLARE @DeletedAreaName VARCHAR(50); DECLARE @DeletedLft INTEGER; DECLARE @DeletedRgt INTEGER; SELECT TOP 1 @DeletedAreaName = SiteAreaName, @DeletedLft = Lft, @DeletedRgt = Rgt FROM directoryLinks WHERE SiteAreaName = '#ARGUMENTS.SiteAreaName#' Oh and I'd use cfqueryparam, but you may have stripped that for the sake of brevity. Auke ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:244619 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: CF Declaring SQL variables
Hi Auke, I think this would have worked but I'm getting a CURSOR error: 'VARCHAR' is not a recognized CURSOR option. I've come across this error a few times before and don't really understand it and the way to fix it. Any ideas. Richard ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:244620 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: CF Declaring SQL variables
On Friday 23 June 2006 13:48, Richard Cooper wrote: 'VARCHAR' is not a recognized CURSOR option. Maybe replace with VARCHAR2 -- Tom Chiverton This email is sent for and on behalf of Halliwells LLP. Halliwells LLP is a limited liability partnership registered in England and Wales under registered number OC307980 whose registered office address is at St James's Court Brown Street Manchester M2 2JF. A list of members is available for inspection at the registered office. Any reference to a partner in relation to Halliwells LLP means a member of Halliwells LLP. Regulated by the Law Society. CONFIDENTIALITY This email is intended only for the use of the addressee named above and may be confidential or legally privileged. If you are not the addressee you must not read it and must not use any information contained in nor copy it nor inform any person other than Halliwells LLP or the addressee of its existence or contents. If you have received this email in error please delete it and notify Halliwells LLP IT Department on 0870 365 8008. For more information about Halliwells LLP visit www.halliwells.com. We are pleased to announce that Halliwells LLP has been voted AIM Lawyer of the Year at the 2005 Growth Company Awards ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:244621 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: CF Declaring SQL variables
Auke's code is working fine for me: DECLARE @MyVar VARCHAR( 3 ); SELECT TOP 1 @MyVar = game_sTeamA FROMtbl_game WHERE game_nID = 1 ; SELECT @MyVar Result: | (No Column Name) --+--- 1 | GER Mingo. Richard Cooper wrote: Hi Auke, I think this would have worked but I'm getting a CURSOR error: 'VARCHAR' is not a recognized CURSOR option. I've come across this error a few times before and don't really understand it and the way to fix it. Any ideas. Richard ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:244622 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: CF Declaring SQL variables
Hi Auke, I think this would have worked but I'm getting a CURSOR error: 'VARCHAR' is not a recognized CURSOR option. I've come across this error a few times before and don't really understand it and the way to fix it. Any ideas. I think only CURSORs are allowed names without a leading '@'. Most likely you are declaring your variables like this: DECLARE DeletedAreaName VARCHAR(50); instead of DECLARE @DeletedAreaName VARCHAR(50); Because (I think) you are declaring the variable without the starting '@', MS-SQL assumes it's a cursor, and therefore complains about the VARCHAR that follows it. ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:244625 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
Re: CF Declaring SQL variables
Hi All, Tried both combinations of both way but couldn't get it to work. In the end I had to break it into multiple queries. [code] !--- GET Delete --- cfquery name=breadcrumb1 datasource=#REQUEST.theDatabase# !---SELECT the values for the Deleted level into variables--- SELECT SiteAreaName, Lft, Rgt FROM directoryLinks WHERE SiteAreaName = '#ARGUMENTS.SiteAreaName#' /cfquery cfset DeletedAreaName = '#breadcrumb1.SiteAreaName#' cfset DeletedLft = '#breadcrumb1.Lft#' cfset DeletedRgt = '#breadcrumb1.Rgt#' !--- Delete --- cfquery name=breadcrumb2 datasource=#REQUEST.theDatabase# !---Perform the deletion--- DELETE FROM directoryLinks WHERE Lft BETWEEN cfqueryparam value=#DeletedLft# cfsqltype=cf_sql_integer / AND cfqueryparam value=#DeletedRgt# cfsqltype=cf_sql_integer /; /cfquery !---UPDATE the table so that the gaps between Lft and Rgt values are removed--- !--- GET Delete --- cfquery name=breadcrumb3 datasource=#REQUEST.theDatabase# UPDATE directoryLinks SET Lft = (CASE WHEN Lft cfqueryparam value=#DeletedLft# cfsqltype=cf_sql_integer / THEN Lft - (cfqueryparam value=#DeletedRgt# cfsqltype=cf_sql_integer / - cfqueryparam value=#DeletedLft# cfsqltype=cf_sql_integer / + 1) ELSE Lft END), Rgt = (CASE WHEN Rgt cfqueryparam value=#DeletedLft# cfsqltype=cf_sql_integer / THEN Rgt - (cfqueryparam value=#DeletedRgt# cfsqltype=cf_sql_integer / - cfqueryparam value=#DeletedLft# cfsqltype=cf_sql_integer / + 1) ELSE Rgt END) WHERE Lft cfqueryparam value=#DeletedLft# cfsqltype=cf_sql_integer / OR Rgt cfqueryparam value=#DeletedLft# cfsqltype=cf_sql_integer / /cfquery [/code] Thanks for all you help. Richard ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:244632 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54