Compilation Of Stored Procs
Hi,
I would like to know if the execution plans of stored procs also get migrated when we do migration to 2005 from 2000 using attachdetach method or we will need to re-run the stored procs?
The thing is when I am running the Stored procs in 2005, its performing really slow in first run.
Any help in his regard is highly appreciated.
Thanks,
Ritesh
View Complete Forum Thread with Replies
Related Forum Messages:
Ignore Compilation Errors For Creation Of Stored Procedures
I have an application that is moving from an home made full text search engine to using the full text indexing engine of SQL 2005. I have a stored procedure that I want to behave as: check documents table to determine whether a full text index for SQL's full text engine has been created. If it has not, query the documentText table (which is the table for my in-house full text search) If it has, use the full text indexing engine My problem is that compilation of the TSQL to create the stored procedure fails when the full text index has not already been created with the followign error: Msg 7601, Level 16, State 2, Procedure My_FullTextSearch, Line 0 Cannot use a CONTAINS or FREETEXT predicate on table or indexed view 'Documents' because it is not full-text indexed. In my test lab, I tried: 1. creating the full text index 2. creating the stored procedure 3. deleting the ful text index which gets me to the desired end result of having a stored procedure that can determine whether or not the full text index has been created yet (the procedure works in this state). But I creating this index as part of this stored procedure creation in production is not an option. My question - Can I somehow tell SQL to ignore the compilation errors it encounters while creating this stored procedure? If not, is there some other way to create this "smart" stored procedure? Here's a code snippet stripped down to the bare minimum to generate the error: CREATE PROCEDURE [My_FullTextSearch] @Term VarChar(1000) AS BEGIN SET NOCOUNT ON; IF NOT OBJECTPROPERTY(OBJECT_ID('Documents'), 'TableHasActiveFulltextIndex')=1 BEGIN Select [DocumentID] from [DocumentText] where [Term] like '%' + LTRIM(@Term) + '%' END ELSE BEGIN Select [key] from FREETEXTTABLE(Documents, Contents, @Term) END END
View Replies !
Stored Procedure Compilation Question: Doing Disparate Things In Aproc
To minimize the very large number of stored procedures typicallyassociated with an application, I have gotten in the habit ofcombining a select, insert, update, and delete all in one procedure,and passing an argument to indicate which to use. (I use defaultvalues for all input params to avoid having to declare them forselects and deletes.) So I'll have just one PersonAdmin proc insteadof PersonGet, PersonInsert, PersonUpdate, and PersonDelete procsWhile this is nice for housekeeping, I wonder what the compiler doeswith such an architecture,and I fear the worst. The select returns arecordset; the others don't.Is this a bad idea?If it is, I really wish SQL would permit some sort of user folderstructure in the proc list.
View Replies !
Problem With Using Stored Procs As I/p To Another Stored Procs
HI, CREATE PROCEDURE PROC1 AS BEGIN SELECT A.INTCUSTOMERID,A.CHREMAIL,B.INTPREFERENCEID,C.CHR PREFERENCEDESC FROM CUSTOMER A INNER JOIN CUSTOMERPREFERENCE B ON A.INTCUSTOMERID = B.INTCUSTOMERID INNER JOIN TMPREFERENCE C ON B.INTPREFERENCEID = C.INTPREFERENCEID WHERE B.INTPREFERENCEID IN (6,7,2,3,12,10) ORDER BY B.INTCUSTOMERID END IF I AM USING THIS PROC AS I/P TO ANOTHER PROC THEN IT GIVES NO PROBLEM AS I CAN USE ? CREATE PROCEDURE PROC2 AS BEGIN CREATE TABLE #SAATHI(INTCUSTOMERID INT,CHREMAIL NVARCHAR(60),INTPREFERENCEID INT,CHRPREFERENCEDESC NVARCHAR(50)) INSERT INTO #SAATHI EXEC PROC1 ST......1, ST......2, END. BUT IF , I USE ANOTHER PROC SIMILAR TO THE FIRST ONE WHICH GIVES SLIGHTLY DIFFERENT RESULTS AND GIVES TWO SETS OF RESULTS,THEN WE HAVE A PROBLEM,HO TO SOLVE THIS :- CREATE PROCEDURE MY_PROC AS BEGIN SELECT A.INTCUSTOMERID,A.CHREMAIL,B.INTPREFERENCEID,C.CHR PREFERENCEDESC FROM CUSTOMER A INNER JOIN CUSTOMERPREFERENCE B ON A.INTCUSTOMERID = B.INTCUSTOMERID INNER JOIN TMPREFERENCE C ON B.INTPREFERENCEID = C.INTPREFERENCEID WHERE B.INTPREFERENCEID IN (23,12,10) ORDER BY B.INTCUSTOMERID END SELECT A.INTCUSTOMERID,MAX(case when A.intpreferenceid = 23 then '1' else '0' end) + MAX(case when A.intpreferenceid = 12 then '1' else '0' end) + MAX(case when A.intpreferenceid = 10 then '1' else '0' end) AS PREFER FROM CUSTOMER GROUP BY A.INTCUSTOMERID ORDER BY A.INTCUSTOMERID END WHICH NOW GIVES ME TWO SETS OF DATA , BOTH REQUIRED THEN HOW TO USE ONE SET OF RESULTS AS I/P TO ANOTHER PROC AND OTHER SET OF RESULTS AS I/P TO YET ANOTHER PROC . CREATE PROCEDURE PROC2 AS BEGIN CREATE TABLE #SAATHI(INTCUSTOMERID INT,CHREMAIL NVARCHAR(60),INTPREFERENCEID INT,CHRPREFERENCEDESC NVARCHAR(50)) INSERT INTO #SAATHI EXEC MY_PROC ST......1, ST......2, END. BUT, HERE I WANT TO USE FIRST DATASET ONLY , HOW TO USE IT ? THANKS.
View Replies !
Stored Procs Are BAD!! BAD, I Tell You!!!
almost choked when i read the following recent post on The Daily WTF (http://thedailywtf.com/) the other day -- Logical Tiers? That Makes No Sense! (http://thedailywtf.com/ShowPost.aspx?PostID=28959) i don't think i can do justice to how utterly stupid that stored procedure is read the comments and have a laugh one of the points made was that stored procedures are bad this twigged something in my memory, so i dug around in my bookmarks, and sure enough, here's another decent discussion about stored procs -- Stored procedures are bad, m'kay? (http://weblogs.asp.net/fbouma/archive/2003/11/18/38178.aspx) enjoy!
View Replies !
.exe From Stored Procs
Hey guys. I am wondering if it is possible to execute an .exe from a stored proc. I have an application that calls a stored proc and I am wanting for that stored proc to call up an app to show certain results. I have no way of doing this on the application itself as I dont have the source code. So, since I do have access to the SQL I am wondering if it could be done there. Thanks tibor
View Replies !
I Need Help With Stored Procs And UDF
First off, this is a cross post which is also located here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=34073 Now, with the following stored procs and UDF, the Result is NULL and I cannot figure out why. What I am doing is calling a stored procedure pass in an OUTPUT variable of type float. This stored proceudre then calls a different stored procedure passing the same OUTPUT variable of type float. The second stored procedure then calls a UDF passing in two variables to be multiplied ans this should set the OUTPUT variable to the result. The UDF does return the correct result to the interior stored procedure, but the interior stored procedure does not pass the value back to the original stored procudure resultint in a Result value = NULL. The code is below, just copy / past, execute and you will see exactly what I mean. Any thoughts? USE NORTHWIND GO CREATE FUNCTION RECTANGULAR_XSECTION (@fWidth float, @fHeight float) RETURNS float AS BEGIN RETURN (@fWidth * @fHeight) END GO CREATE PROCEDURE usp_shapes_GetRectangularXSection @fResult float OUTPUT AS declare @fWidth float, @fHeight float SELECT @fWidth = 108, @fHeight = 10 SELECT @fResult = [dbo].[RECTANGULAR_XSECTION](@fWidth, @fHeight) SELECT @fResult AS CalledProcedureOkHere GO CREATE PROCEDURE usp_shapes_GetXSection @fResult float OUTPUT AS EXECUTE usp_shapes_GetRectangularXSection @fResult SELECT @fResult AS CallingProcedure_NULL? GO declare @fResult float EXECUTE usp_shapes_GetXSection @fResult SELECT @fResult as OutsideCallingProcedure_NULL? GO DROP FUNCTION RECTANGULAR_XSECTION GO DROP PROCEDURE usp_shapes_GetRectangularXSection GO DROP PROCEDURE usp_shapes_GetXSection GO Mike B
View Replies !
SQL Stored Procs
can anyone help me out.... i need to compare a date that was retrieved from the database and the system date then it must be coded in the stored procs of the database.. help!!!!
View Replies !
New To Stored Procs
I am trying to improve my SQL and reduce the number of connections my website is making to the server. Currently I have a stored procedure that gets all the games (and their details) for a single user which works fine which uses a WHERE userid = @userid which is an Int value. I now need to create a new procedure which brings back the to all their "friends" (again by their userid). How is it best to do this? I originally tried to do a WHERE userID IN (@userid) but was unable to work out what variable type to use for @userid. Is it best to do a single query in this way or is there a way to use the existing SP, loop through the collection of userids and join the result together into a single set to return? If an IN is the best route, what is the correct datatype for the variable?
View Replies !
IF Statement In Stored Procs... Help!
Hi all! I am not an expert in Stored Procs. I would like to build one for a product list that would return a default value without using output parameters, if possible. Ultimately, I wouldn't be opposed to it. It currently looks like this: CREATE PROCEDURE ProductsByVendorNo ( @VendorNum nvarchar(24) ) AS SELECT P.ProductID AS ProductID, P.ProductShortName AS ProductName, P.ProductDesc AS ProductDesc, U.UnitDesc AS Unit, P.VendorProductNumber AS VendorNumber, V.VendorName AS VendorName, P.Price AS Price, P.ImageThumb AS ImageThumb FROM tblProducts AS P INNER JOIN tblUnitCodes AS U ON P.UnitCode=U.UnitCode INNER JOIN tblVendors AS V ON P.VendorID=V.VendorID WHERE V.VendorsVendorNo = @VendorNum AND P.Inactive = 0 ORDER BY ProductName, VendorNumber I would like for it to return a default, constant value for the URL in the ImageThumb field, if this one is empty. I could not find good documentation of how to use IF statements for this case, i.e. to alter the return of just one field. Suggestions? Any input is highly appreciated. Thanks in advance, Mili Skikic
View Replies !
Transactions And Stored Procs
All, I'm relatively new to stored procs (not to SQL or SQL Server) and I am trying to get transactions to work within a stored proc. Here is the code: ( --define the parameters that are needed @userID char(32), @userName varchar(50), @status char(10), @type char(10), @password varchar(50), @firstName varchar(100), @lastName varchar(100), @email varchar(200), @domain varchar(50), @pwdExpiry int, @badLogin int, @lastLogin datetime, @full varchar(8000), @read varchar(8000), @noaccess varchar(8000) ) AS BEGIN TRAN tmp1 --First, insert the user into the system INSERT INTO ptsUsers(UserID, UserName, Status, Type, Password, FirstName, LastName, Email, DomainName, PasswordExpiry, BadLoginAttempts, LastLoginDate) values(@userID, @userName, @status, @type, @password, @firstName, @lastName, @email, @domain, @pwdExpiry, @badLogin, @lastLogin); --Now, we need to add the function access edges for the user declare @arrayValue char(32) declare @rightID char(32) declare @sepPos int while patindex('%,%',@full)<>0 BEGIN select @sepPos = patindex('%,%' , @full) select @arrayValue = left(@full, @sepPos - 1) -- replace the value with an empty string select @full = stuff(@full, 1, @sepPos, '') --create and parse the new id declare @strID char(32),@tmpStr varchar(40) set @tmpStr = newid(); set @strID = REPLACE(@tmpStr,'-','') --get the access right id for full control select @rightID = (Select AccessRightID from ptsAccessRights where Name = 'Write') if(@rightID IS NOT NULL) --insert the records that are full access INSERT INTO ptsFunctionAccessEdges(FunctionAccessEdgeID, FunctionID, AccessRightID, UserID) VALUES(@strID, @arrayValue, @rightID, @userID) else RAISERROR(50100,15,1) END COMMIT TRAN tmp1 IF @@TRANCOUNT > 0 RAISERROR(50101,15,1) ROLLBACK TRAN tmp1 The transaction does not rollback when any errors occur at all. Any advice/help?
View Replies !
Question Regarding Stored Procs
Hello,It might be a basic question, but there it goes:I have a store procedure that first checks if the record exists and, ifit doesn't, inserts the new record.Is the scenario below possible?(thread1) USER1 -> check if record "abc" exists(thread2) USER2 -> check if record "abc" exists(thread1) USER1 -> "abc" doesn't exist(thread2) USER2 -> "abc" doesn't exist(thread1) USER1 -> add "abc" as new record(thread2) USER2 -> add "abc as new record (OPS, this is an error,because "abc" already exists, it was just inserted by USER1)I am wondering if this kind of concurrent, multi-threaded accesshappens with stored procedures.If yes, can I execute a procedure from start to finish without anyother simultaneous procedure interrupting?I appreciate any information about this.Leonardo.
View Replies !
Stored Procs And Db_owner
I have some users that I need to run stored procedures, but they can'tseem to run them unless they are in the db_owner role of the database.How do I give them access to run the stored procs without giving themthe complete rights of the db_owner role?Thanks in advance.
View Replies !
Errors And Stored Procs
Ok, I've read somewhere(which I'm looking for again : ) that said that there are errors like DeadLock that kills the execution of a stored proc and there are other errors that do not necessarily kill the rest of the execution of the stored proc. Is that true? If so does anyone have any links I can read. What I'm seeing is a bad id in the foreign key and I think what is happening is that there was a unique constraint error on the first insert but the stored proc continued executing and used the bad id later on in the stored proc. I do know I can use the @@error and will start using it but I need more proof to agree or not agree with my theory. Thanks ahead of time for any information you can give me either way. DMW
View Replies !
Views And Stored Procs.
Is there any performance loss by setting up a view and creating a stored procedure to return a recordset from a view versus setting up the stored procedure to return the recordset from the tables directly? What way should I do this? Mike B
View Replies !
Help - Updating Stored Procs !!
Hi all. First post on here, so please excuse any ignorant parts of my question :) We've recently had to migrate an application from one server to another, and had lots of problems getting it to work (NT4/SS7 -> 2K3/SS2K5). After much digging around I found the info on SQL server 2k5 changing the SUSER_NAME to SUSER_SNAME (I think from reading the change was actually from SQL Server 2000 - that correct ?). Anyway I updated some of our stored procedures to correct that issue, and things *seem* to be working again (<-- famous last words, I know :eek: ), but I've been trying to find details of any other changes, particularly command changes, that I may need to make to our stored procedures. To be honest I've found the info on Microsoft's main site and technet site next to useless - all seems to discuss very generic high-level procedures for database migration etc.. I didn't even find the SUSER change on there. Could anyone point me to some useful information on other changes to look out for (within the SP's) ?? Thanks in advance for your help, and for taking the time to read this :beer:
View Replies !
Encrypted Stored Procs
Hey yall I ran into something interesting today and was wondering how one would do this. I have some 3rd party stored procs and one was kicking out a truncate error so I took it upon myself to investigate the stored proc that was kicking out this error. So when I tried viewing the sp, I received an error:*****Encrypted object is not transferable, and script could not be generated.***** and then it brings up a blank editing screen. First I believe this was a custom error message as it just doesnt seem like the way SQL Server would have presented it. So how would someone prohibit viewing of a stored proc like this? Thanks
View Replies !
Concurrent Stored Procs?
Hi all I have a stored proc that runs every 4 hours - as a job. The stored proc takes about 3-5 minutes to comple, depending on number of records. To do testing we run that stored proc manually, also. Sometimes 2 or more people may run the same stored proc without knowing that the other person is running. This may create duplicates entries once processed. What I want to know is, Is there a way to check if that stored procedure is currently running. If so it wont run second time concurrently. (May be semapohres,mutex or something like that?) (I am trying not to use a table to store whether the stored proc is running or not) Thanks in advance. Rochana
View Replies !
Extended Stored Procs?
Does anyone have any suggestions on where to go to find out how to write extended stored procedures for SQL Server using Delphi? Will the extended stored procedures / dlls written to work against 6.5 work with 7.0?
View Replies !
Stored Procs And Parameters
I have a stored proc that is run periodically which I execute with a DTS package. The problem is that I have to update a field for each record selected by this stored proc with a specific date. I need to prompt the operator for this date so I can use this value.
View Replies !
Debugging Stored Procs With VB
Having some trouble getting the SQL debugger working...anyone see the following error: Cannot load the DLL SDI, or one of the DLLs it references. Reason 126(The specified module could not be found.) Thanks! Tim
View Replies !
Not Normal Will Stored Procs Help
I will be taking over a database that has almost no pk's or relations(this is not my choice, but a vendors) Management is looking at stored procs to improve performance, but I am wondering if the db is in this state will there really be a gain. I am pushing for normalization first, but if anybody has any ideas or opinions I would appreciate
View Replies !
Using Stored Procs In Subqueries
In the interested of code reuse, is it possible to use a stored procedure in a subquery (I couldn't get it to work, but I figured I'd ask anyway)? ex: Select * from employees where employeeid IN(exec getStaffList 1000) where 1000 is a parameter passed into the proc... I just don't know if I want to create procs for every time we want to call getStaffList (which has some complicated heirarchy code) for use in another way... Any other ideas? I've tried many different versions along these same lines, including syntax changes, and an inner join on getStaffList 1000... to no avail... thanks, Amy
View Replies !
Using Stored Procs In A DTS Package
I am trying to set up a DTS package that selects data from one table on server A into another table on server B. I want to do a select statement that will do the following: select store_name from store (server A) where date_created >= (select max(date_created) from store (server B) I use EM 7.0 to manage all of my extracts, however, the data is moving from a Syabase (adaptive Server)onto another Syabase(adaptive server) machine. Unfortunately, there is no functionality for a linked server connection. I tried the following, (which doesn't error out), but is not displaying the source columns in the destination tab of the DTS package when setting up the transformations. declare @maxdate datetime exec serverB.dbo.sp_max_date_from_store @maxdate select store_name from store --(server A) where date_created >= @store Any help or suggestions would be greatly appreciated! trevorb
View Replies !
Conversion To Stored Procs
Hi, We are trying to figure out the benefit of converting all the updates/inserts/deletes inline sql to stored procedures in our existing live apps. In the past, my team was using inline sql with coldfusion for everything. Can somebody help me understand if it's all worth it to go back and change or should we just move from this point forward? Your comments and oppinions are welcome Zoey
View Replies !
Security On Stored Procs On Dev Db
I want to "deny" create, update,and delete access on the dbo stored procs that are in the database, but do not want take away dbo owner access. is this possible? can i create a role and deny access on a particular table in msdb? or a system table in the user table. Thus preventing the developers on the box access to update any of the dbo owned sp's and have them create their own user-owned stored procs? this is sql7, sp3, development box. thanks,
View Replies !
Set ANSI_DEFAULTS In Stored Procs
I am looking for some information on where to set the SQL-92 Settings Statements and why. I have seen the statements, such as "SET ANSI_DEFAULTS ON" or "SET ANSI_NULLS ON", set before the drop of a procedure, before the create procedure command and inside the proc itself. It seems the proc behaves differently depending on where these settings are made. I have not been able to find the final word from Microsoft on this. I know a number of these settings cause the proc to recompile but does it matter if it is outside or inside the proc? If the settings are before the create procedure command then how does the proc know to follow these settings when the proc is called from an app? Thanks
View Replies !
Using Dynamic SQL In Stored Procs
Hi, I have read in many articles that Dynamic SQL should not be used in Stored Procedures as it is not a Best Practice. So Can anyone tell me how to handle the following scenario without using Dynamic SQL in Procs. The scenario is as follows I have to write a Procedure which will generate a Report from a Table. For this purpose I have to Select about 20 columns from a Table (lets say Table A). Now the report has 5 filters which are completely optional. I mean the user might fill few of the filters or all the filters or none of the Filters So can anyone help me out in this scenario because my "where" clause is completely Dynamic and I am unable to understand how to handle my where clause without writing Dynamic Queries. Also I am trying to write this query on SQL Server 2000. If anyone can give me some examples or articles which can be of help it would be great. Please help Regards Vineed
View Replies !
Where Do You Put Common Stored Procs?
I have a few stored procs that I use from more than one database. There has to be a place I can put these so I don't have a copy of the proc in each DB, right? Where do you put them and how do you reference them? Thanks. J
View Replies !
Help Understanding Stored Procs
I am having trouble understanding how to correctly use stored procs. Here is what I think the process is. Correct me where I am wrong. I am developing a read-only program with VB 2005 as a front end and SQL Server back end. The user will enter an ID# for search criteria which will be passed as a parameter to a stored proc. I want to create a stored proc that alters a view by changing the ID# the view filters on. A dataset will be created in the front end from that view. So in SSMS, I create a new proc like this: CREATE PROC {blah, blah} @IDnum AS BEGIN ALTER VIEW {blah, blah} AS SELECT {blah, blah} FROM {blah} WHERE blah.ID = @IDnum END I would run the code to create the proc, then modify it to an ALTER PROC. I've tried this without success. What am I missing. Yes, I am new to this. Thanks for the help
View Replies !
Stored Procs Script
Can someone please point me in the right direction (guidance or url to a utility or article) as to how we can write a script to scan all of the stored procedures in our database for any reference to a field name were are about to change? Also, can we use such a script to do the actual change from the old field name to the new one? Thanks!
View Replies !
ARITHABORT AND STORED PROCS
I wrote a stored procedure and set it as a schedule. it has no problem when I execute this SP in query analyzer. But it will show error when I execute it in schedule job. I think the main reason is I have created a DDL trigger that will fire when DDL_DATABASE_LEVEL_EVENTS happens. Any solution? SELECT failed because the following SET options have incorrect settings: 'ARITHABORT'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or query notifications and/or xml data type methods. [SQLSTATE 42000] (Error 1934). The step failed.
View Replies !
Logging CPU And IO Cost Of Stored Procs
We use SQL Server 2005 and we use lots of stored procedures. Each time a stored procedure run we log the name, execution time and username so we can identify trends and long-running procedures. I would like to add the actual CPU and IO cost of execution to this log. Is there a way to get it? This type of information is viewable in SQL Server's performance tools - so there must be some way to get it. Can someone point me in the right direction please? Thanks!
View Replies !
SQLDatasource, Stored Procs && Parameters
Hi, I'm having an issue trying to send parameters to a SQLDatasource object. I"m creating it in code (and I need it to stay there) I have determined that the stored procs called with no parameters work fine. I start having problems when I have any parameters. Interestingly, it doesn't crash. It just fails to run (the onselected event never fires). dsUser is a protected SQLDatasource property repMain is a repeater on the aspx sheet lstUser is a stored proc with one varchar(10) parameter called cSort Here is my current code that will result in no called to StatementCompleted and no data. Pull cSort parameter from the proc and it works just fine. Obviously I'm setting it wrong. string cSelect = "dbo.lstUser"; dsUser = new SqlDataSource(); dsUser .ConnectionString = GetConStr(); dsUser .SelectCommand = cSelect; dsUser .SelectParameters.Add( "cSort", TypeCode.String, "" ); dsUser .Selected += StatementCompleted; repMain.DataSource = dsUser ; TIA, Nick Hustak
View Replies !
Error Handling/ Stored Procs
Hi, I'm doing some fairly basic updates with stored procedures. 99% of them affect one row. I've jsut discovered that I can't get the value of @@rowcount and @@error to return as output parameters (if I check one, the other one gets reset!). My theory is then to return the rowcount and if it's not = 1, then I know I've had a problem. If I begin a transaction in vb.net and call each proc in the required order and check each step that rowcount = 1, is this a reliable method of ensuring no errors have occurred?Thanks.
View Replies !
Working With Images In Stored Procs
What is the best way to store images in sql server and then retrieve them with stored proc's using vb.net/asp.net? There seems to be a lot of different opinions about just saving the img tag, the path, etc. I only need to store 15 icons.... appreciate any help I can get. Thanks soggy coder seattle
View Replies !
Can Stored Procs Run After Handle Is Closed?
I have written a stored proceedure for MSSQL that needs to run for hours ata time. I need to execute it from C++ code. The current code does:nRet = SQLDIRECTEXEC(hstmt, "exec stored_proc", SQL_NTS)followed shortly after by aFree_Stmt_Handle(hstmt) //roughlyThe stored proc currently dies with the statement handle, not fullypopulating the table I need it to.I need to either know when the proc finishes so I can close the handle afterthat, or allow the proc to run independently on the server no matter whatthe program is doing (is exited, etc), either of these is fine.Please Help! Thanks in advance!Joseph
View Replies !
Stored Procs - Specifying ORDER BY As A Parameter
hi all, hope someone can help....i'm having trouble calling an SP where the ORDER BY operator is specified asa parameter when the SP is calledmy SP is.....CREATE PROCEDURE dbo.sp_CustSearch (@SearchFor VARCHAR(80) , @SortOrderVARCHAR(50))ASBEGINSELECT first_name, last_name, postcode , address, townFROM customer WITH (nolock)WHERE (UPPER (last_name) LIKE '%' + @SearchFor + '%'OR UPPER(address.postcode) = @SearchFor )ORDER BY @SortOrderENDGOthe line causing the problem is ORDER BY @SortOrderthe error i get on checking the syntax is:"Error 1008: The SELECT item identified by the ORDER BY number 1 contains avariable as part of the expression identifying a column position. Variablesare only allowed when ordering by an expression referencing a column name"anyone know how to solve this? i'm guessing it's something simple.enclosing @SortOrder in single quotes gives, unsuprisinlgy, unsortedresults.trying ORDER BY '[' + @SortOrder + ']' gives the same error asabovethe only way i've managed to get it working so far is to dynamically buildthe SQL statement and then execute that at the end. it's a little messywhich was why i was trying to get the above working.thanks in advance.
View Replies !
Verifying The Validity Of Stored Procs
I have about 1,000 stored procs that need to be migrated to a new database. The problem im finding is that some of them are no longer valid (they may reference a table or column that no longer exists). Is there an easy way I can audit all the procs verifying which are still valid and which need to be fixed or removed. If I attempt to import (or copy a database to a new server) this seems to cause me a problem. I get an import error at 99% with the error msg displaying just the column name that has a problem. I then have to go through all the procs and find the delinquent one and fix or remove it. Any help would be greatly appreciated.
View Replies !
Dynamically Created Stored Procs???
Okay. Scenario: We as a company have several companies that request custom reports from us. However, the custom reports that they select will generally always have the same fields (and formulas) once they make up their minds on what works for them. From what I know, Stored Procs are usually faster at running things unless the parameters are changing too drastically that they get passed. This being the case, it would seem like a good case for creating a stored proc per report. This would alleviate the possability that the server chooses an execution plan that works great some of the time but the rest of the time run lousy. So these thoughts being laid out, is there a good,nice,easy, convenient way to generate/alter a stored proc, either by another stored/extended proc, or by dynamic sql going to the server? Or if not, is there some round-about yet effective way of doing this? Thank you in advance for any help. -ZanderB
View Replies !
Corrupt Stored Procs On SQL Server 6.5
Hi Recently I have experienced the following scary scenario; Users report a problem with an app, on diagnosis it is found that a bunch of SPs in SQL Server seem to be corrupt. That is, when the code for them is listed, the 'Create Procedure..' line and several DECLARE lines are missing. Often the SP starts off in the middle of a variable name!! Perhaps entries in the syscomments table have become corrupted? Has anyone seen this problem before - is it perhaps a known bug in SQL Server 6.5? Regards,
View Replies !
Searching Thru Stored Procs Via The Sys Tables
Basically, I want to be able to have a stored procedure that will search through all the stored procedures looking for a given string and returning the names of all the stored procs that contain that string value. I know I can script it off and then do a text search in Notepad or whatever, but I figured there must be a more elegant way to do it. More than likely dealing with the DB sys tables. Is there already a tool in SQL Server that does this? Or has anybody had a chance to roll their own? Thanks, Tim
View Replies !
[COMPILE] Lock On Stored Procs
To all, When a stored proc is executed in SQL server 2000, it is holding a EXCLUSIVE [COMPILE] lock on the proc and the proc os getting recompiled every time it is executed. This is happening with most of the procs that are called from this proc. When multiple users are executing the same process they are having to wait until the other users are done compiling the procs. The lapse time is growing exponentially with multiple users. I have looked at several places to find a solution for this. Microsoft Articles Q243586 and Q263889 have provided me with some options; but at this point, I need a miracle. All these procs users temp tables. I have got the code changed to replace most of them with Table datatypes (on SQL2K only) . Some of them still need to use temp tables as they are cross referenced by multiple procs. I am hopeful, there is some one out there who has dealt with this kind of situations before. Any ideas/sugessions are greatly appreciated.. Thanks
View Replies !
Executing Extended Stored Procs???
I've written a very simple extended stored proc--little more than what VC++ 6.0's ext stored proc wizard generates--set up the xp in the master database, and eventually want to execute it from a trigger defined on a table in another database... I've tested the xp in Query Analyzer. If the DB is set to 'master', the xp runs (exec xp_InputTrigger), no problem. If I change databases and try to run the xp, I get: Server: Msg 2812, Level 16, State 62, Line 1 Could not find stored procedure 'xp_InputTrigger'. Keying "exec master.xp_InputTrigger", also fails: Could not find stored procedure 'master.xp_InputTrigger'. I've checked permissions--all seem to be set right. Anyone have any insight for me here? Many thanks, mjo
View Replies !
Stored Procs - Managing Permissions
Does anyone know how to multiple select stored procedures and deal with the permission sin one go? I know you can do this easily in SQL 6.5 but not in SQL 7. I have to select each stored procedure individually to manage permissions.
View Replies !
Building Dynamic SQL In Stored Procs
We are migrating from a file-server Access Database to a SQL server backend and Access front end system. I'm using ADO to access the data off the server but am implementing most of the business logic in stored procedures. All logic was coded in VBA earlier but i'm having to move that to T-SQL for performance issues. In many cases I have dynamically constructed SQL statements in code but I'm having some trouble in T-SQL. How can I do this in T-SQL? ' This is some VB code that shows how the query differs based on a parameter. If Me![Sorting] = 1 Then Me![ControlNumber].RowSource = "SELECT [DVD_Projects_Table].[DVD_Number], [Title] & "" : "" & [ID_Number] AS Display,__ [DVD_Projects_Table].Date FROM [DVD_Projects_Table] __ WHERE ((([DVD_Projects_Table].System) = IIf([Forms]![DVD_Projects_Form]![SystemFilter] = 1, ""525"", ""625""))) And __ (([DVD_Projects_Table].Active) = IIf([Forms]![DVD_Projects_Form].[ActiveOnly] = True, Yes, __ [DVD_Projects_Table].[Active]))) ORDER BY [DVD_Projects_Table].Title;" Else Me![ControlNumber].RowSource = "SELECT [DVD_Projects_Table].[DVD_Number], [ID_Number] & "" : "" & [Title] AS Display,__ [DVD_Projects_Table].Date FROM [DVD_Projects_Table]__ WHERE ((([DVD_Projects_Table].System) = IIf([Forms]![DVD_Projects_Form]![SystemFilter] = 1, ""525"", ""625""))) And __ (([DVD_Projects_Table].Active) = IIf([Forms]![DVD_Projects_Form].[ActiveOnly] = True, Yes, __ [DVD_Projects_Table].[Active]))) ORDER BY Int(Right([ID_Number],Len([ID_Number])-4));" End If This is the ideal sp that would do what I want but it is obviously incorrect. How can I get this logic implemented. I need to construct an SQL query based on the input parameters in a stored procedure. CREATE PROCEDURE [procDVDProjectsList] @SortBy as bit, @ActiveOnly as bit, @SysFilter as integer AS SELECT CASE @SortBy /* Display Title first */ WHEN 0 THEN [DVD_Number], [Title] + " : " + [ID_Number] AS Display, [DVD_Projects_Table].[Date] /* Display Number first */ WHEN 1 THEN [DVD_Number], [ID_Number] + " : " + [Title] AS Display, [DVD_Projects_Table].[Date] END FROM [DVD_Projects_Table] WHERE CASE @SysFilter /* List all */ WHEN 0 THEN /* List only NTSC */ WHEN 1 THEN [DVD_Projects_Table].[System] = "525" /* List only PAL */ WHEN 2 THEN [DVD_Projects_Table].[System] = "625" END AND CASE @ActiveOnly /* List All */ WHEN 0 THEN /* List only active */ WHEN 1 THEN [DVD_Projects_Table].Active = True END ORDER BY CASE @Sortby /* Sort Alpha */ WHEN 0 THEN [DVD_Projects_Table].Title /* Sort Numeric */ WHEN 1 THEN Right([ID_Number],Len([ID_Number])-4) END Thanks for your help, -Sumit Malik
View Replies !
Code Control & SQL Stored Procs
Has anyone ever used Visual SourceSafe to control SQL's stored procedures? I hear it is unreliable to manage stored procedures in SQL7. Do any of the DBA's out there manage source code? I'm looking for a software product that I can deploy development code (including stored procs, VB apps) from a development environment to a production environment. Dev ---> Testing ----> Prod thanks,
View Replies !
Creating Sql Strings In Stored Procs
Hi Guys, I have written a piece of code in a stored procedure that builds a string called "filter$" based on fielde in a table. How do I use this string as my where clause? in vb I would use: rs.open filter$,cn I hope this makes sense and someone can help me
View Replies !
[COMPILE] Lock On Stored Procs
To all, When a stored proc is executed in SQL server 2000, it is holding a EXCLUSIVE [COMPILE] lock on the proc and the proc os getting recompiled every time it is executed. This is happening with most of the procs that are called from this proc. When multiple users are executing the same process they are having to wait until the other users are done compiling the procs. The lapse time is growing exponentially with multiple users. I have looked at several places to find a solution for this. Microsoft Articles Q243586 and Q263889 have provided me with some options; but at this point, I need a miracle. All these procs users temp tables. I have got the code changed to replace most of them with Table datatypes (on SQL2K only) . Some of them still need to use temp tables as they are cross referenced by multiple procs. I am hopeful, there is some one out there who has dealt with this kind of situations before. Any ideas/sugessions are greatly appreciated.. Thanks
View Replies !
|