Creating System Stored Procedure In 7.0
Mar 14, 2001
Can I create system stored procedure in sql 7.0?
After I used 'alter' to modify a system sp, it's category
change from 'system' to 'user'. Is there way to change it back?
Thanks a lot!
Xiao
View 1 Replies
ADVERTISEMENT
May 15, 2007
Hi.I am between beginner and intermediate level of knowledge of sql server.I am dealing with an sql server 2005 situation (oracle also but thats anotherthread/story).I need to assemble a process that an end user can use easily to update adatabase. The update consists of some column lengthening, checks to make surenew data will fit in columns after the ddl is executed, and then generatingnew data (changing primary key column data and keeping all the referingobjects/rows in sync). I also don't want to have an error leave things in abad state.I'm wondering if there is anything special to look out for, and if there areany suggestions on approach. Here is my current approach:write a single stored procedure to do all the work.have it check for existence of table01_bak and table02_bakdelete them if they existrecreate themcopy table01 and table02 to table01_bak and table02_bakcalculate the new primary key values neededmake sure they will fit (I need to bail out and tell the user to make anadjustment at this point if they will not)start a transactiongenerate the new primarky key values and insert themupdate all the other tables that refer to the still existing primary keys topoint them to the newly generated onesdelete all the old rows using the original primary keyscommit a transactiondelete the table01_bak and table02_bakthanksJeffJeff Kish
View 3 Replies
View Related
Mar 28, 2007
I have a stored procedure that calls a msdb stored procedure internally. I granted the login execute rights on the outer sproc but it still vomits when it tries to execute the inner. Says I don't have the privileges, which makes sense.
How can I grant permissions to a login to execute msdb.dbo.sp_update_schedule()? Or is there a way I can impersonate the sysadmin user for the call by using Execute As sysadmin some how?
Thanks in advance
View 9 Replies
View Related
May 13, 2008
Greetings:
I have MSSQL 2005. On earlier versions of MSSQL saving a stored procedure wasn't a confusing action. However, every time I try to save my completed stored procedure (parsed successfully ) I'm prompted to save it as a query on the hard drive.
How do I cause the 'Save' action to add the new stored procedure to my database's list of stored procedures?
Thanks!
View 5 Replies
View Related
Apr 7, 2006
We recently upgraded to SQL Server 2005. We had several stored procedures in the master database and, rather than completely rewriting a lot of code, we just recreated these stored procedures in the new master database.
For some reason, some of these stored procedures are getting stored as "System Stored Procedures" rather than just as "Stored Procedures". Queries to sys.Objects and sys.Procedures shows that these procs are being saved with the is_ms_shipped field set to 1, even though they obviously were not shipped with the product.
I can't update the sys.Objects or sys.Procedures views in 2005.
What effect will this flag (is_ms_shipped = 1) have on my stored procedures?
Can I move these out of "System Stored Procedures" and into "Stored Procedures"?
Thanks!
View 24 Replies
View Related
Feb 24, 2005
How can I create a dbo/system stored procedure, not dbo/user SP.
One more thing, if I created a new database TimeDB, I see nothing in stored procedure folder, how can see something (system procedures) as I knew that in SQL 97, we can see something (system procedures).
View 6 Replies
View Related
Mar 1, 2007
I am attempting to develop a stored proc that will do the following:
1) Take as an input parameter the filepath of a local directory
2) Return a recordset showing all files contained in the local directory
At the code level, I am attempting to do the following:
1) use system.io class to iterate through each file of a given local directory
2) parse out a union query to show all file names and their system creation times
3) insert the parsed sql into a sqldatareader, and send that out via a sqlpipe to the caller.
After compiling and deploying the CLR stored proc, I get the following when I try to execute:
Msg 6522, Level 16, State 1, Procedure spclr_wcl_get_file_info, Line 0
A .NET Framework error occurred during execution of user defined routine or aggregate 'spclr_wcl_get_file_info':
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
System.Security.SecurityException:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption)
at System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption)
at System.IO.Directory.GetFiles(String path)
at StoredProcedures.spclr_wcl_get_file_info(String str_dir)
This occurs even though I've set the SQL Server service to run as a local administrator on the machine (ie, the account should have full rights to virtually any local directory or file).
I found the following article which I thought might resolve:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=494009&SiteID=1
but when I include the WindowsImpersonationContext, etc., I instead get the following:
Msg 10312, Level 16, State 49, Procedure spclr_wcl_get_file_info, Line 0
.NET Framework execution was aborted. The UDP/UDF/UDT did not revert thread token.
Was hoping someone could illuminate as to what I'm doing wrong? Below is a code sample. TIA.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.IO;
using System.Diagnostics;
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void spclr_wcl_get_file_info(string str_dir)
{
// this clr stored proc will read all files in the trans log directory and return
// a recordset with file names and create dates.
//impersonate the calling user
System.Security.Principal.WindowsImpersonationContext newContext;
newContext = SqlContext.WindowsIdentity.Impersonate();
//enumerate files in directory, use to parse out union select query, return table with file names and create times.
string str_sql = "";
System.DateTime d_date;
FileInfo obj_fsi;
string[] str_arr_files = Directory.GetFiles(str_dir);
foreach(string str_file in str_arr_files)
{
obj_fsi = new FileInfo(str_dir + str_file);
if (obj_fsi.Exists)
{
d_date = obj_fsi.CreationTime;
str_sql += "SELECT CHAR(39)" + str_file + "CHAR(39) AS [file_name], ";
str_sql += d_date.ToLongDateString() + " file_creation_time UNION ";
}
}
// parse off the last 'union'
if (str_sql.Length > ("UNION ").Length)
str_sql = str_sql.Substring(0, str_sql.Length - ("UNION ").Length);
// use sql to send dataset back to caller.
SqlCommand obj_cmd = new SqlCommand();
obj_cmd.Connection = new SqlConnection("Context connection=true");
obj_cmd.Connection.Open();
obj_cmd.CommandText = str_sql;
SqlDataReader obj_reader = obj_cmd.ExecuteReader();
SqlPipe obj_pipe = SqlContext.Pipe;
obj_pipe.Send(obj_reader);
//clean up
obj_reader.Close();
obj_cmd.Connection.Close();
}
};
View 4 Replies
View Related
Jun 27, 2007
Hi,
I'm using the sp_start_job system stored procedure to run a job on the SQL Server Agent. The sp_start_job stored procedure takes a parameter called, step_name where you can begin execution from that step. My problem is that I only want to run that one step of the job rather than that step and every step after it. Is there a way to only execute one particular step? Or a safe way to successfully terminate the process after that step has finished. Any input would be much appreciated. Thanks.
View 4 Replies
View Related
Oct 13, 2006
Is it possible to create a stored procedure that execute a delete command from a table whose name is specified as a parameter of the stored procedure?Thank you
View 3 Replies
View Related
Apr 3, 2007
ALTER PROCEDURE companyinsert@companyid INT IDENTITY(1,1) NOT NULL,@companyname varchar(20),@address1 varchar(30)ASINSERT INTO companymaster ( companyname, address1)VALUES (@companyname,@address1)i don't want the companyname having the same names are recorded again with the different company id..Can anyone help me and modify my code according it's giving error...in the @companyid.It is being done in sql server 2005 with asp.net C# 2005
View 1 Replies
View Related
May 6, 2007
I have some script for creating the table i want but i need some help creating a Stored Procedure. That will Insert the UserId from the aspnet_Users Table (UserId) into the UserId Column in my table. So when a user creates an account it will put that users id into my table. The data will be retrieved by a FormView and the user can Update their info threw the FormView control..
I just need to associate the UserId from the aspnet_User Table with my table, so the data is stored per UserId in a new row for each new user..create table dbo.custom_Profile (
UserId uniqueidentifier not null Primary Key,
IamWeAre nvarchar(50) null,
InterestedIn nvarchar(256) null,
IntroTitle nvarchar(100) null,
TellOthers nvarchar(MAX)null,
MaritalStatus nvarchar(20) null,
BodyType nvarchar(50) null,
Race nvarchar(20) null,
Smoking nvarchar(20) null,
Drinking nvarchar(20) null,
Drugs nvarchar(20) null,
Education nvarchar(256) null)
go
View 15 Replies
View Related
Mar 16, 2008
I have a table (displayed in a gridview) of services we provide. I have another table (the logfile) that displays the current status of those services. This GridView displays the service and current status.When a new service is created there is obviously no status yet. This causes a problem because my stored procedure (below) does not display that new service in my GridView. How can I ensure EVERY service is included in my dataset regardless of whether or there is a status? (and how can I get away from having to group by all the time?)
select s.servicename, s.opr, c.commentid,c.comment, c.etic, t.statusfrom svc_service sinner join svc_comment c on c.serviceid = s.serviceidinner join svc_status t on t.statusid = c.statusidgroup by s.servicename, s.opr, c.commentid, c.comment, c.etic, t.status
TIA,
Jon
View 4 Replies
View Related
Jul 8, 2004
I have an inline sql query which i want to convert to a stored procedure.
The query is simplified as follows:
string sql = "SELECT * FROM property_property WHERE Location = " + location;
if(state != null) sql += " AND State = " + state;
if(cost !=null) sql += " AND Cost = " + cost;
The query is created depending on variable states; there are 7 in the real one which together creates the required query to query the database. Im not sure how/if it can be converted in to a stored proc
I know some of the basics and managed to convert every other query except this.
Any help would be appreciated
View 3 Replies
View Related
Dec 4, 2005
I already know how you create a stored procedure to add information to a database or retrieve a value for one record. But I don't know how to create a stored procedure that will retrieve many records for a certain querystring value.
Here's my simple stored procedure to show one record:
CREATE PROCEDURE DisplayCity(@CityID int)AS
SELECT City From City where CityID = @CityIDGO
My code for displaying the City:
Sub ShowCity()
Dim strConnect As String
Dim objConnect As SqlConnection
Dim objCommand As New SqlCommand
Dim strCityID As String
Dim City As String
'Get connection string from Web.Config
strConnect = ConfigurationSettings.AppSettings("ConnectionString")
objConnect = New SqlConnection(strConnect)
objConnect.Open()
'Get incoming City ID
strCityID = request.params("CityID")
objCommand.Connection = objConnect
objCommand.CommandType = CommandType.StoredProcedure
objCommand.CommandText = "DisplayCity"
objCommand.Parameters.Add("@CityID", CInt(strCityID))
'Display SubCategory
City = "" & objcommand.ExecuteScalar().ToString()
lblCity.Text = City
lblChosenCity.Text = City
objConnect.Close()
End Sub
Here's the code I'd like to get help with changing into a stored procedure:
Sub BindDataList()
Dim strConnect As String
Dim objConnect As New System.Data.SqlClient.SQLConnection
Dim objCommand As New System.Data.SqlClient.SQLCommand
Dim strSQL As String
Dim dtaAdvertiser As New System.Data.SqlClient.SQLDataAdapter()
Dim dtsAdvertiser As New DataSet()
Dim strCatID As String
Dim strCityID As String
Dim SubCategory As String
Dim SubCategoryID As String
Dim BusinessName As String
Dim City As String
'Get connection string from Web.Config
strConnect = ConfigurationSettings.AppSettings("ConnectionString")
objConnect = New System.Data.SqlClient.SQLConnection(strConnect)
objConnect.Open()
'Get incoming querystring values
strCatID = request.params("CatID")
strCityID = request.params("CityID")
'Start SQL statement
strSQL = "select * from Advertiser,AdvertiserSubCategory, Categories, SubCategories, County, City"
strSQL = strSQL & " where Advertiser.CategoryID=Categories.CategoryID"
strSQL = strSQL & " and Advertiser.AdvertiserID=AdvertiserSubCategory.AdvertiserID"
strSQL = strSQL & " and AdvertiserSubCategory.SubCategoryID=SubCategories.SubCategoryID"
strSQL = strSQL & " and Advertiser.CountyID=County.CountyID"
strSQL = strSQL & " and Advertiser.CityID=City.CityID"
strSQL = strSQL & " and AdvertiserSubCategory.SubCategoryID = '" & strCatID & "'"
strSQL = strSQL & " and Advertiser.CityID = '" & strCityID & "'"
strSQL = strSQL & " and Approve=1"
strSQL = strSQL & " Order By ListingType, BusinessName,City"
'Set the Command Object properties
objCommand.Connection = objConnect
objCommand.CommandType = CommandType.Text
objCommand.CommandText = strSQL
'Create a new DataAdapter object
dtaAdvertiser.SelectCommand = objCommand
'Get the data from the database and
'put it into a DataTable object named dttAdvertiser in the DataSet object
dtaAdvertiser.Fill(dtsAdvertiser, "dttAdvertiser")
'If no records were found in the category,
'display that message and don't bind the DataGrid
if dtsAdvertiser.Tables("dttAdvertiser").Rows.Count = 0 then
lblNoItemsFound.Visible = True
lblNoItemsFound.Text = "Sorry, no listings were found!"
else
'Set the DataSource property of the DataGrid
dtlAdvertiser.DataSource = dtsAdvertiser
'Set module level variable for page title display
BusinessName = dtsAdvertiser.Tables(0).Rows(0).Item("BusinessName")
SubCategory = dtsAdvertiser.Tables(0).Rows(0).Item("SubCategory")
SubCategoryID = dtsAdvertiser.Tables(0).Rows(0).Item("SubCategoryID")
City = dtsAdvertiser.Tables(0).Rows(0).Item("City")
'Bind all the controls on the page
dtlAdvertiser.DataBind()
end if
objCommand.ExecuteNonQuery()
'this is the way to close commands
objCommand.Connection.Close()
objConnect.Close()
End Sub
View 4 Replies
View Related
Jun 19, 2000
How can I create a Stored Procedure name within stored procedure ?
Example:
CREATE PROCEDURE A_1000
AS
..............
..............
..............
create procedure B_2000
..............
..............
..............
Is that possible ?
I'm trying to create a SP within the SP.
Thankx for ur time
Thankx a lot
View 1 Replies
View Related
Jun 11, 2007
I need to add up the number of people who joined this month and compare that number to the number of people who joined last month and display the results in a report and I have never done a stored procedure and I was wondering if it would be ease to do?
FirstName..LastName.....StartedDate
Randy......Simpson......5/4/2007 10:00:00 PM
Steve......Rowe.........5/2/2007 10:00:00 PM
Eric.......Dickerson....5/4/2007 10:00:00 PM
Gloria.....Sanches......5/1/2007 12:00:29 AM
Andres.....Marcelino....5/1/2007 12:06:31 AM
katie......ryan.........6/4/2007 12:08:35 AM
Denise.....River........6/4/2007 12:27:14 AM
Kellog.....Stover.......6/5/2007 12:37:20 AM
Glenn......Sanders......6/1/2007 12:42:40 AM
View 3 Replies
View Related
Jul 20, 2005
Im trying to create a stored procedure that selects everything from afunction name that im passing in through a parameter..create procedure SP_selectall(@functionname varchar(25))asselect * from @functionamegoI keep getting this error:Server: Msg 137, Level 15, State 2, Procedure SP_selectall, Line 5Must declare the variable '@functioname'.Whats the issue?
View 1 Replies
View Related
Jan 2, 2008
I am using a web application using asp.net 1.1 vs 2003.
i am using sql server authentication where users are using their sql server user id and sql server saved passwords.
how can i change their passwords inside the sql server?
is there a system sp that allows one to pass one's user id and then change password.
I will need to call that sp from a user defined store dprocedure and pass the parameters and that will change the password on the sql server.
thanks
View 3 Replies
View Related
Dec 17, 2003
Is it possible to have single stored procedure which can return Weekly, Monthly, Quaterly and Yearly Report.
User input for Queries:
Weekly : Start Date & End Date
Monthly: Month & Year (Eg. Jan 2003, May 2004)
Quarterly: Quarter & Year (First Quarter 2003, ThirdQuarter 2004)
Yearly: Year
Currently I have 4 different Stored Procedure 1 for each reporting system.
I have seen that one can use CASE in Stored procedure.....
Pls give suggestion !!!
View 20 Replies
View Related
Jan 2, 2004
Thx to all who helped me for Stored Procedure previously
Here is what I have:
3 Drop Down Boxes:
1) List of property
2) Ticket Status
3) Tech Name
All 3 Drop boxes have default value of "All"
So, if all 3 drop boxes are "All" ie.
list of property = All
Ticket status = All
Tech Name = All
Query pulls up all records from database and displays it.
Lets say if I select Tech Name is XYZ then query should pull out all property, all ticket status by Tech XYZ.
Now my previous developer has if else case and he has total 9 query for doing all this. He has used SQL along with C# code.
I am trying to modify this if-else and convert it into Stored Procedure. Is there a way I can handle all with 1 stored procedure ?
Previous Reporting works like charm........
View 17 Replies
View Related
Nov 29, 1999
Hi,
Is it possible to store the output of a SQL Server 7.0/6.5 System Stored Procedure (eg. xp_fixeddrives, sp_spaceused, etc.) in a table, possibly with a Select Into?
All help will be greatly appreciated.
Thanx in advance.
Craig
View 4 Replies
View Related
Nov 5, 2002
I want to have a Stored procedure call another stored procedure gathering the info from some of the information SP#1 and use it calling SP#2...
For example sp_Help returns columns when executed (Name, Owner, Object_type).
So how can I reference the Name column and pass it to SP#2
Exec sp_Help
...?
SP#2 name=sp_help.Name ???
Thanks
Richard
View 1 Replies
View Related
Apr 25, 2007
Hello
I wonder if I can generate the "CREATE TABLE" sentence given the name of a table by means of a stored procedure.
Thanks a lot.
View 4 Replies
View Related
Sep 30, 2014
Is it possible to access the procedure which scripts a table to new query? My goal is to automate the creation of some tables.
View 4 Replies
View Related
Sep 24, 2007
How do I pass system variables to a stored procedure? Is it possible to have an OLE DB transformation with the following sql command: exec InsertIntoLog @MachineName, @TaskName...? Do I have to use a Derived Transformation first to 'convert' variables into columns and then use exec InsertIntoLog ?, ? ...
Thanks for the help.
View 8 Replies
View Related
Apr 2, 2007
Want help in creating the stored procedure of company where id is the PrimaryKey in the table companymaster which is created in sql server 2005.1 ALTER PROCEDURE companyinsert
2
3 @companyid int,
4 @companyname varchar(20),
5 @address1 varchar(30)
6
7 AS
8
9 INSERT INTO companymaster
10 ( companyname, address1)
11 VALUES (@companyname,@address1) Procedure or Function 'companyinsert' expects parameter '@companyid', which
was not supplied.
The id is to be created autogenerate in the sequence number.There should be no duplicated companyname with different ids in same table.Apart from the above error can anyone pls give me or tell me the code or modify the stored procedure according to the above..thanxs....
View 5 Replies
View Related
Aug 28, 2007
I am trying to create stored procedure i Query analyzer in visual studio 2005. I am havingdifficulty though. Whenever I press the execute button, here is the error message I get:
Msg 102, Level 15, State 1, Procedure MarketCreate, Line 21Incorrect syntax near 'MarketName'.
Here is the stored procedure. Note that the very first column in named "MarketId" but I did notinclude it in the stored procedure since it should be auto generated.
USE [StockWatch]GO/****** Object: StoredProcedure [dbo].[MarketCreate] Script Date: 08/28/2007 15:49:26 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO
CREATE PROCEDURE [dbo].[MarketCreate]
( @MarketCode nvarchar(20), @MarketName nvarchar(100), @LastUpdateDate nvarchar(2), @MarketDescription nvarchar(100))
ASINSERT INTO Market( MarketCode MarketName LastUpdateDate MarketDescription)VALUES( @MarketCode @MarketName @LastUpdateUser @MarketDescription)
View 2 Replies
View Related
Jan 3, 2008
I was trying to create a new stored procedure. It's pretty straight forward using Insert Into. Here's what I wrote:
CREATE PROCEDURE dbo.InsertPicks@ID varchar,@Race int,@P1 varchar,@P2 varchar,@P3 varchar,@P4 varchar,@P5 varchar,@P6 varchar,@P7 varchar,@P8 varchar,@P9 varchar,@P10 varchar,
INSERT INTO tblPicks(pRace, pPlayer, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)VALUES(@Race,@ID,@P1,@P2,@P3,@P4,@P5,@P6,@P7,@P8,@P9,@P10) RETURN
I first wrote the T-SQL code myself, but when I opened the Query Builder so I could validate it and check it. It validated and when I executed it, it worked great and inserted a new record into the table. Yet, when I closed the Query Builder, and tried to save the Stored Procedure (which I assume is how you create it) I get an error that there is a Incorrect Syntax near "Insert". I see nothing wrong with the syntax, and it worked fine in the Query Builder. What am I doing wrong?
Thanks,
Bob
View 2 Replies
View Related
Mar 23, 2008
Is there a way I can use one SQL server 2005 (full edition not express) Stored procedure that can execute a .SQL file as if it were in the SQL management studio Query window?
I have the situation where I have some .SQL file which were created with the 'Create to File' option in SQL Management studio. I then want to send them to a user who can execute them to create a SP on his SQL server without having to run the SQL management tools.
Regards
Clive
View 8 Replies
View Related
May 21, 2008
I am using SQL Server Express within visual studio and am needing to create a stored procedure. The proble is that every time I finish and close it then it asks me if I want to save the changes which of course I want to.
But then it always comes up with a message box that says "invalid object name" followed with the name of the stored procedure.
??? why? I try creating a stored procedure from scratch or copying the code of another stored procedure. It alway gives me that message and does not let me save the stored procedure. I tried changing the default name of "dbo.storedprocedure1" or even leaving it as is and always I get the message that says "invalid object name: dbo.storedprocedure1" and it does not let me save the procedure.
What am I doing wrong?
View 5 Replies
View Related
Feb 2, 2004
The code is as below:
--Drop procedures if they exsit
if exists (SELECT * FROM master.dbo.sysobjects WHERE id = object_id(N'[dbo].[sp_PagedItems]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_PagedItems]
GO
if exists (SELECT * FROM master.dbo.sysobjects WHERE id = object_id(N'[dbo].[sp_PagedItemsByTime]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_PagedItemsByTime]
GO
if exists (SELECT * FROM master.dbo.sysobjects WHERE id = object_id(N'[dbo].[sp_selectedEventMessage]') AND OBJECTPROPERTY(id,N'IsProcedure')=1)
drop procedure [dbo].[sp_selectedEventMessage]
GO
--Definitions of procedures
USE LanDeskDB
GO
CREATE PROCEDURE sp_PagedItems
(
@QueryVARCHAR(1000),
@Pageint,
@RecsPerPageint,
@startDateVARCHAR(100),
@endDateVARCHAR(100),
@allTimeint,
@flagint
)
AS
BEGIN
SET NOCOUNT ON
DECLARE @SQL VARCHAR(2000)
DECLARE @Order VARCHAR(200)
DECLARE @TotalBIGINT
CREATE TABLE #TempTable
(
TempTableID BIGINT NOT NULL PRIMARY KEY IDENTITY(1,1),
EventLogID BIGINT ,
EventDateTime datetime,
MachineID INT ,
TypeID INT ,
SessionID INT ,
SourceID INT ,
MessageID BIGINT ,
UserID INT,
CategoryNumber INT,
EventID INT
)
IF (@flag = 1)
BEGIN
SET @Order = 'ORDER BY EventDateTime'
END
IF (@flag = 2)
BEGIN
SET @Order = 'ORDER BY SessionID,EventDateTime'
END
IF (@flag = 3)
BEGIN
SET @Order = 'ORDER BY TypeID,EventDateTime'
END
IF (@flag = 4)
BEGIN
SET @Order = 'ORDER BY CategoryNumber,EventDateTime'
END
IF(@allTime <> 1)
BEGIN
IF(LEN(@Query)>1)
BEGIN
SET @Query = @Query+'AND EventDateTime>='''+@startDate+''' AND EventDateTime <= '''+@endDate+''''
END
ELSE
BEGIN
SET @Query = 'WHERE EventDateTime>='''+@startDate+''' AND EventDateTime <= '''+@endDate+''''
END
END
SET @SQL=
'INSERT INTO #TempTable (EventLogID,EventDateTime,MachineID,TypeID,SessionID,SourceID,MessageID,UserID,CategoryNumber,EventID)'+
'SELECT EventlogID,EventDateTime,MachineID,TypeID,SessionID,SourceID,MessageID,UserID,CategoryNumber,EventID FROM EventLog '+
@Query+' '+@Order
EXEC (@SQL)
CREATE TABLE #TempTableTwo
(
TempTableTwoID BIGINT NOT NULL PRIMARY KEY IDENTITY(1,1),
TempTableID BIGINT,
EventLogID BIGINT ,
EventDateTime datetime,
MachineID INT ,
TypeID INT ,
SessionID INT ,
SourceID INT ,
MessageID BIGINT ,
UserID INT,
CategoryNumber INT,
EventID INT,
)
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page - 1) * @RecsPerPage
SELECT @LastRec = @Page * @RecsPerPage+1
INSERT #TempTableTwo
SELECT * FROM #TempTable T
WHERE T.TempTableID >@FirstRec AND T.TempTableID < @LastRec
SELECT TempT.EventLogID AS EventLogID,TempT.EventDateTime AS EventDateTime,
Ma.MachineName AS MachineName,Se.SessionName AS SessionName,Ty.TypeName AS TypeName,
TempT.CategoryNumber AS CategoryNumber,Us.UserName AS UserName,So.SourceName AS SourceName,
TempT.EventID AS EventID
FROM #TempTableTwo TempT,Machines Ma,Types Ty,Sessions Se,Sources So,Users Us
WHERE TempT.MachineID = Ma.MachineID AND TempT.TypeID = Ty.TypeID AND TempT.SessionID = Se.SessionID
AND TempT.SourceID = So.SourceID AND TempT.UserID = Us.UserID
SELECT COUNT(*) FROM #TempTable
DROP TABLE #TempTable
DROP TABLE #TempTableTwo
SET NOCOUNT OFF
END
GO
CREATE PROCEDURE sp_PagedItemsByTime
(
@QueryVARCHAR(1000),
@Page int,
@RecsPerPage int,
@startDateVARCHAR(100),
@endDateVARCHAR(100),
@allTime int
)
AS
BEGIN
EXEC sp_PagedItems @Query,@Page,@RecsPerPage,@startDate,@endDate,@allTime,1
END
GO
CREATE PROCEDURE sp_selectedEventMessage
(
@EventLogID int
)
AS
BEGIN
SELECT Ma.MachineName,Ev.EventDateTime,Se.SessionName,Ty.TypeName,So.SourceName,Me.MessageDescription
FROM EventLog Ev,Sessions Se,Types Ty,Sources So,Messages Me,Machines Ma
WHERE Ev.EventLogID = @EventLogID AND Ev.SessionID = Se.SessionID AND Ma.MachineID = Ev.MachineID
AND Ev.TypeID = Ty.TypeID AND Ev.SourceID = So.SourceID AND Ev.MessageID = Me.MessageID
END
GO
I got the error messge as
Server: Msg 2714, Level 16, State 5, Procedure sp_PagedItems, Line 107
There is already an object named 'sp_PagedItems' in the database.
Server: Msg 2714, Level 16, State 5, Procedure sp_PagedItemsByTime, Line 13
There is already an object named 'sp_PagedItemsByTime' in the database.
Server: Msg 2714, Level 16, State 5, Procedure sp_selectedEventMessage, Line 12
There is already an object named 'sp_selectedEventMessage' in the database.
But I already delete those procedures before I create them. Could anyone give some suggestion?
View 2 Replies
View Related
Aug 30, 2012
I am working with SQL Server 2005 Express and have written a query which works well in when run it in the managment console as a select query.
When I try to create a stored procedure out of it, I get the following error:
Code:
Msg 102, Level 15, State 1, Procedure sp_SegmentationList_ByorderID, Line 20 Incorrect syntax near ';'.
Procedure is below:
Code:
USE [ARC_Test]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_SegmentationList_ByorderID]
@OrderID int
[code].....
View 3 Replies
View Related
Jan 14, 2004
Hello,
I'm trying to create a store procedure from an interface which is similiar to Query Analyzer, but I can't get it to work and I don't get an error message...so I'm not sure what error I am receiving. Please see the below sp_get_topics (#1) which is not saving and sp_get_topics (#2 works). Thanks in advance....
--#1--
CREATE PROCEDURE [sp_get_topics] AS
SELECT t_1.Topic, t_1.Message, t_1.Create_Date, t_2.Username
FROM t_1 WITH (READUNCOMMITTED) LEFT OUTER JOIN
t_2 WITH (READUNCOMMITTED) ON t_1.User_ID = t_2.ID
GO
--#2--
CREATE PROCEDURE [sp_get_topics]
AS
SELECT Topic, Message, Create_Date
FROM t_1
GO
View 11 Replies
View Related