> I would like to keep it all in the same function without having to use an 
> if clause.

I think you'll have to use an "if" at some level to make it work.

If you add to your function:
<cfargument name="userID" required="no" type="numeric">

Then in your query add:
SELECT userID, userType, userAccessLevel, userName, firstName, lastName
FROM Users
WHERE active = '1'
<cfif structkeyexists(arguments,"userID")>
 AND userID = <cfqueryparam cfsqltype="cf_sql_bigint" 
value="#arguments.userID#" />
</cfif>

This way you can either pass in or not pass in the userID, and you should 
get the results you're looking for.

-- Josh




----- Original Message ----- 
From: "Steve Sequenzia" <[EMAIL PROTECTED]>
To: "CF-Talk" <[email protected]>
Sent: Thursday, July 12, 2007 1:11 PM
Subject: Query in a function


>I am not sure if this is possible but here is what I am trying to do.
>
> I have a function that queries the database (MSSQL) for all users:
>
> <cffunction name="getUsers" returntype="query" access="remote">
>
>    <cfquery name="queryUsers" datasource="#application.ds#">
>
>            SELECT userID, userType, userAccessLevel, userName, firstName, 
> lastName
>            FROM Users
>            WHERE active = '1'
>
>        </cfquery>
>
>        <cfreturn queryUsers>
>
>    </cffunction>
>
> I was going to add an argument to it for userID and change the where 
> clause to (WHERE active = '1' and userID = '#arguments.userID#'). That 
> should work fine but what I would like to do is still use the same 
> function to retrive all the users not just the one with the selected 
> userID.
>
> I would like to keep it all in the same function without having to use an 
> if clause.
>
> The end result would be that if I pass the userID to it I get back a query 
> with just the one record that matches the userID but if I do not pass the 
> userID to it, it returns all of the records.
>
> Like I said, I am not sure if this is even possible.
>
> Any help on this would be great.
>
> Thanks in advance.
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion MX7 and Flex 2 
Build sales & marketing dashboard RIA’s for your business. Upgrade now
http://www.adobe.com/products/coldfusion/flex2?sdid=RVJT

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283637
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to