| Author |
Topic |
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-10-15 : 17:46:51
|
| Hi Everyone,I am currently working on a web application where wher users perform hundreds of searches each day. These searchs are on such thing as customer name, or customer phone number.What I would like to do is some how "remember" what searches (maybe most recent 20) a user has preformed and display them on the web application. All of my search queries are in stored procedures. I may be over simplifing it but is there a way that in each of my search SPs I could run an additional SP that would record the USER ID, the SP that was ran, and the parameters that were sent.Basically I want some way to record what searches were ran by the user so they can quickly run them again from my web application if needed.Thanks,RyanRyan EverhartSBCSBC. Going Beyond the Call! |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-15 : 18:06:12
|
well u nned another table with columnsUserID, SpName, Parametersin which you save the search parameters.then you just build a dynamic sql to execute sproc with parameters and that's it...Go with the flow & have fun! Else fight the flow |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-10-16 : 01:32:23
|
| The Sproc that inserts into the logging table could also drop the oldest if there were more than, say, 20 for that userkristen |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-10-17 : 18:51:25
|
quote: Originally posted by spirit1 well u nned another table with columnsUserID, SpName, Parametersin which you save the search parameters.
Spirit this is exactly what I want to do. When I am inserting my values into the other table you mentioned above how do I know what stored proc is being called? Is there a variable available during the execution of the SP that tells me what the name SP running is?RyanRyan EverhartSBCSBC. Going Beyond the Call! |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-18 : 03:52:17
|
emmm.... as i see it:you do a search in your sproc, so you know what sproc is ran. so you can hardcode it's name into it.insert into newTableselect SYSTEM_USER, 'yourSprocName', parametersyou do this insert in the sproc.Go with the flow & have fun! Else fight the flow |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-10-18 : 10:32:00
|
| Spirit,Thanks for you help so far. After working on this a bit this is the data I've collected so far.user procname parametersp1944 usp_TE_getSearchMAC '8168471454%','AccountNum',2002044sp1944 usp_TE_getSearchMAC '81684714%','AccountNum',2002044sp1944 usp_TE_getSearchMAC '81684713%','AccountNum',2002044Now my question is how do I write another stored procedure that would run the search again using the information above... Say I need to run exec usp_TE_getSearchMAC '81684713%','AccountNum',2002044How do I do that dynamically?I tried "EXEC sp_executesql" but I don't think I had the parameters set right.Thanks for your help.RyanRyan EverhartSBCSBC. Going Beyond the Call! |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-18 : 10:41:20
|
will this help?create procedure spNewSprocasdeclare @sql varchar(8000)set @sql = 'exec usp_TE_getSearchMAC ''81684713%'',''AccountNum'',2002044'--orset @sql = 'exec ' + procname + ' ' + parameter from MyTable where user = 'someUserName'exec @sqlgoGo with the flow & have fun! Else fight the flow |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-10-18 : 11:04:44
|
| Spirit,This is what I have...-- query to get information i needOMITTED-- set up sql variable for use in dynamic exectutionSET @sql = 'EXEC ' + @procname + ' ' + @parameter-- execute dynamic sqlEXEC @sqlThis is what my @sql variable looks likeEXEC usp_TE_getSearchMAC '3143852025%','AccountNum',2002819However I get the following error.Server: Msg 2812, Level 16, State 62, Line 21Could not find stored procedure 'EXEC usp_TE_getSearchMAC '3143852025%','AccountNum',2002819,'re8686','usp_TE_getSearchMAC''.Any thoughts? I've tried taking the 'exec' off of the @sql parameter and I get the same error. Thanks for you help on this, I'm sorry my question is dragging out this long.RyanRyan EverhartSBCSBC. Going Beyond the Call! |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-18 : 11:15:21
|
you say your @sql looks like:EXEC usp_TE_getSearchMAC '3143852025%','AccountNum',2002819so when you do EXEC @sql i believe it translates to:EXEC 'EXEC usp_TE_getSearchMAC ...'so have your @sql look like:@sql = 'usp_TE_getSearchMAC ''3143852025%'',''AccountNum'',2002819'and the do:exec @sqlhope it's clear...Go with the flow & have fun! Else fight the flow |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-10-18 : 11:15:31
|
| Spirit,Disregard my last question. I got it to work with the some parentheses.EXEC (@sql)Thanks for all your help!RyanRyan EverhartSBCSBC. Going Beyond the Call! |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-18 : 11:16:14
|
mybe you should post the whole code that you do. it sure would be easier to figure it out...Go with the flow & have fun! Else fight the flow |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-10-18 : 11:22:29
|
| Spirit,Here is the code that works! I really appreciate your help on this. Once I get all the details worked out I believe this will really benefit my users greatly!Ryan-- declare local variables to be used in this procDECLARE @procname varchar(75), @parameter varchar(250), @sql varchar(5000)-- get the procname and the search paramemeters for use in the dynamic statement belowSELECT @procname = ProcName, @parameter = ParameterFROM TESearchWHERE Search_ID = 429ORDER BY PostDate desc-- set up @sql variable for use in dynamic sql belowSET @sql = 'EXEC ' + @procname + ' ' + @parameter-- execute dynamic sqlEXEC (@sql)Ryan EverhartSBCSBC. Going Beyond the Call! |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-18 : 11:28:30
|
hey great for you.jsut one question:what does SCB stand for in your signature?Go with the flow & have fun! Else fight the flow |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-10-18 : 11:30:22
|
| SBC is the company I work for.... www.sbc.com.Ryan EverhartSBCSBC. Going Beyond the Call! |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-18 : 11:32:36
|
nice site...Go with the flow & have fun! Else fight the flow |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-10-18 : 12:34:29
|
| Spirit,One more question. Below is teh same code that I posted above with a one addition',@rcdcnt OUTPUT,@resultset OUTPUT'I have added the above code to the EXEC line to get 2 fields out of the stored proc in addition too the query results. When I run the dynamic SQL that you and I created the query results come out just fine, however I do not get any values for the 2 variables, @rcdcnt and @resultset. I know those values are being passed. I just can't seem to grab them correctly. I'll post my code again to get any of your thoughts.CREATE PROCEDURE [usp_TE_getSavedSearch] (@rcdcnt INT OUTPUT,@resultset TINYINT OUTPUT)AS-- declare local variables to be used in this procDECLARE @procname VARCHAR(75), @parameter VARCHAR(250), @sql VARCHAR(5000) -- get the procname and the search paramemeters for use in the dynamic statement belowSELECT @procname = ProcName, @parameter = ParameterFROM TESearchWHERE Search_ID = 429ORDER BY PostDate desc-- set up @sql variable for use in dynamic sql belowSET @sql = @sql + 'EXEC ' + @procname + ' ' + @parameter + ',@rcdcnt OUTPUT,@resultset OUTPUT'-- execute dynamic sqlEXEC (@sql)Ryan EverhartSBCSBC. Going Beyond the Call! |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-18 : 13:12:37
|
they aren't set because they're in another batch.are you sure your sproc runs ok?because you have @sql VARCHAR(5000) which equates to nullthen you do SET @sql = @sql + 'EXEC ...' which again equates to null because null + string is nullusing variables in from different batches can be done with use on global temp tables: ##tempTableGo with the flow & have fun! Else fight the flow |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-10-18 : 14:21:56
|
| Yea the proc does run okay because I am seeing the results in my application for the query itself, just not the two variables mentioned above. Also if I skip the dynamic SP we created all together and runEXEC usp_TE_getSearchMAC '3143852025%','AccountNum',2002819,'re8686','usp_TE_getSearchMAC',@rcdcnt OUTPUT,@resultset OUTPUTI get the query output as well as the two variables. Can you tell me a little more about the global temp tables?RyanRyan EverhartSBCSBC. Going Beyond the Call! |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-10-18 : 14:25:24
|
| Spirit, I apologize, no need for you to explain global temp tables themselves.. I just found some information on them in books online. Ryan EverhartSBCSBC. Going Beyond the Call! |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-18 : 14:30:12
|
it's basically a temporary table that can be called from many batches... Go with the flow & have fun! Else fight the flow |
 |
|
|
jim_rii
Starting Member
4 Posts |
Posted - 2004-11-08 : 15:36:23
|
| I just came across this post and was wondering if anyone has any suggestions on taking these recorded searches and creating a complex search. What I mean by this is giving the user the ability to take these recorded searches and being able to put them together (i.e. displaying a resultset for SearchID 98 and SearchID 99). Any sugestions on how to accomplish this??jim |
 |
|
|
Next Page
|