Transact SQL :: Fine Tune Procedure / Accessed By Multiple Users

Oct 13, 2015

i have a report that runs on a huge table rpt.AgentMeasures  , it has 10 months worth of data (150 million records as of today and will keep increasing).  i have pasted my proc below , the other tables that are joined to this huge table do not have more then 3k records.This report will be accessed by multiple users (expecting 20 ppl). as of now this reports runs for 5 mins if i pull for 1 month worth of data. if it is wise to use temp tables.

ALTER proc [rpt].[Get_Metrics]
@MinDate DATETIME,
@MaxDate DATETIME,
@Medium Varchar(max),
@footPrint varchar(max),

[code]...

View 10 Replies


ADVERTISEMENT

Transact SQL :: Log What Users Accessed Which Databases

Nov 9, 2015

I'd like to find out who is accessing various databases and log the time they did so.

Is there a way to do this? I just need the account name and the time logged and then to write to a table so I can query it.

View 2 Replies View Related

Fine-tune Query

Apr 24, 2008

Hi,
I have a query as mentioned below:

SELECT BillCurrencyID,DistD,Amount,PartnerFlag1
FROM Factsales_tab_Dtls (NOLOCK)
WHERE (sales_year =2007 OR sales_year=2008)
AND Country ='US'

1) Table Factsales_tab_Dtls is having more than 5.5 million of records.

2) It is having 32 columns.

3)There's nonclusetered index on columns sales_year & country
4)The query takes longer time for execution

Please help me fine-tune the query

View 1 Replies View Related

Script To Log/record The Users Who Accessed My Database

Jul 10, 2006

Hi,

I am hosting my database on a third-party Microsoft SQL server. The guest user is "Off". But, I am not sure if any one else is accessing/viewing/editing my database contents.

Can I know/log/record the users/logins who are viewing/accessing my database. Is there any script or any exisitng machnism which can be used to track these users.

Also, are there any things that I should take care with my database from outside users.


Thanks
-Sudhakar

View 2 Replies View Related

Script To Log/record The Users Who Accessed My Database

Jul 10, 2006

Hi,

I am hosting my database on a third-party Microsoft SQL server. The guest user is "Off". But, I am not sure if any one else is accessing/viewing/editing my database contents.

Can I know/log/record the users/logins who are viewing/accessing my database. Is there any script or any exisitng machnism which can be used to track these users.

Also, are there any things that I should take care with my database from outside users.


Thanks
-Sudhakar

View 1 Replies View Related

Script To Log/record The Users Who Accessed My Database

Jul 10, 2006

Hi,I am hosting my database on a third-party Microsoft SQL server. The guest user is "Off". But, I am not sure if any one else is accessing/viewing/editing my database contents. Can I know/log/record the users/logins who are viewing/accessing my database. Is there any script or any exisitng machnism which can be used to track these users.Also, are there any things that I should take care with my database from outside users.Thanks-Sudhakar

View 1 Replies View Related

Transact SQL :: Send Email To Multiple Users Based On A Column

May 15, 2015

I have a query running and returning 3 columns, user name, e-mail and device name

SELECT DISTINCT v_R_User.Full_User_Name0 AS 'User full Name', v_R_User.Mail0 AS 'E-Mail', _RES_COLL_DEV00144.Name
FROM         v_R_System INNER JOIN
                      v_R_User ON v_R_System.User_Name0 = v_R_User.User_Name0 INNER JOIN
                      _RES_COLL_DEV00144 ON v_R_User.User_Name0 = _RES_COLL_DEV00144.UserName INNER JOIN
                      v_GS_COMPUTER_SYSTEM ON v_R_System.ResourceID = v_GS_COMPUTER_SYSTEM.ResourceID
 Where v_R_User.Mail0 <> ''
ORDER BY 'User Full Name'

From here I would like to generate an e-mail to each user (like mail merge) to each user in the table an include their machine name. I can do it with PS, but rather have it run directly from SQL. Is it possible?

View 9 Replies View Related

SQL Server Admin 2014 :: List Of Users That Accessed A Table

Jul 22, 2015

I'm trying to find out what tables are being used in a Database.

I don't want the last User but the User and the Dates.

I have a script that return the last user but that is not going to work.

The following script returns the last user but not all users and the Login Name:

ITH LastActivity (ObjectID, LastAction) AS
(
SELECT object_id AS TableName,
last_user_seek as LastAction
FROM sys.dm_db_index_usage_stats u
WHERE database_id = db_id(db_name())

[Code] .....

View 2 Replies View Related

Transact SQL :: Stored Procedure For Total Count For New Users

Jul 14, 2015

I need to create a stored procedure for total count of the user's. If  User from front end  invites other user to use my tool, that user will be stored into a table name called "test",lets say it will be stored as"Invited 1 User(s)" or if he invites 2 users it will store into table as "Invited 2 User(s)."

But now we have changed the concept to get the ISID (name of the user)  and now when ever the user invites from the front end, the user who have invited should stored in two tables "test" and " test1" table .

After we get the data into test and test1 table i need the total count of a particular user from both tables test and test1.

if i invite a user , the name of the user is getting stored in both test and test1 tables.Now i want to get the count of a user from both tables which should be 1,but its showing 2.

Reason: Why i am considering the count from 2 tables is because before we were not tracking the usernames and we were storing the count in single test table.,but now we are tracking user names and storing them in both tables(test and test1).

Here is my sample  code:

I need to sum it up to get the total user's from both the table but I should get 1 instead of 2 

SELECT
(select distinct COUNT(*) from dbo.test
where New_Values like  '%invited%'
and Created_By= 'sam'
+
(select distinct count (*)  from dbo.test1
where invited_by ='sam'

View 8 Replies View Related

What Is The Solution For This Internal Error EnsureMyReportsExists: Users Folder Not Found When My Reports Accessed

Nov 1, 2007

Any help would be apprecaited....

aspnet_wp!library!1!11/01/2007-09:36:59:: e ERROR: Throwing Microsoft.ReportingServices.Diagnostics.Utilities.InternalCatalogException: An internal error occurred on the report server. See the error log for more details., EnsureMyReportsExists: Users folder not found when My Reports accessed.;
Info: Microsoft.ReportingServices.Diagnostics.Utilities.InternalCatalogException: An internal error occurred on the report server. See the error log for more details.
aspnet_wp!library!1!11/01/2007-09:37:04:: i INFO: Exception dumped to: C:Program FilesMicrosoft SQL ServerMSSQL.4Reporting ServicesLogFiles flags= ReferencedMemory, AllThreads, SendToWatson
aspnet_wp!webserver!1!11/01/2007-09:37:04:: e ERROR: Reporting Services error Microsoft.ReportingServices.Diagnostics.Utilities.InternalCatalogException: An internal error occurred on the report server. See the error log for more details.


10/31/07 14:54:06, ERROR , SQLDUMPER_UNKNOWN_APP.EXE, AdjustTokenPrivileges () failed (00000514)
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Input parameters: 4 supplied
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ProcessID = 2160
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ThreadId = 0
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Flags = 0x0
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDumpFlags = 0x0
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, SqlInfoPtr = 0x053F5860
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, DumpDir = <NULL>
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExceptionRecordPtr = 0x00000000
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ContextPtr = 0x00000000
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExtraFile = <NULL>
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, InstanceName = <NULL>
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ServiceName = <NULL>
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 11 not used
10/31/07 14:54:06, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 15 not used
10/31/07 14:54:10, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 7 not used
10/31/07 14:54:10, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDump completed: C:Program FilesMicrosoft SQL ServerMSSQL.4Reporting ServicesLogFilesSQLDmpr0001.mdmp
10/31/07 14:54:10, ACTION, aspnet_wp.exe, Watson Invoke: No
10/31/07 15:25:56, ERROR , SQLDUMPER_UNKNOWN_APP.EXE, AdjustTokenPrivileges () failed (00000514)
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Input parameters: 4 supplied
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ProcessID = 2160
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ThreadId = 0
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Flags = 0x0
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDumpFlags = 0x0
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, SqlInfoPtr = 0x07E31E9C
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, DumpDir = <NULL>
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExceptionRecordPtr = 0x00000000
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ContextPtr = 0x00000000
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExtraFile = <NULL>
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, InstanceName = <NULL>
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ServiceName = <NULL>
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 11 not used
10/31/07 15:25:56, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 15 not used
10/31/07 15:25:59, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 7 not used
10/31/07 15:25:59, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDump completed: C:Program FilesMicrosoft SQL ServerMSSQL.4Reporting ServicesLogFilesSQLDmpr0002.mdmp
10/31/07 15:25:59, ACTION, aspnet_wp.exe, Watson Invoke: No
10/31/07 15:28:01, ERROR , SQLDUMPER_UNKNOWN_APP.EXE, AdjustTokenPrivileges () failed (00000514)
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Input parameters: 4 supplied
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ProcessID = 2160
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ThreadId = 0
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Flags = 0x0
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDumpFlags = 0x0
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, SqlInfoPtr = 0x07E32A04
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, DumpDir = <NULL>
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExceptionRecordPtr = 0x00000000
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ContextPtr = 0x00000000
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExtraFile = <NULL>
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, InstanceName = <NULL>
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ServiceName = <NULL>
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 11 not used
10/31/07 15:28:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 15 not used
10/31/07 15:28:04, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 7 not used
10/31/07 15:28:04, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDump completed: C:Program FilesMicrosoft SQL ServerMSSQL.4Reporting ServicesLogFilesSQLDmpr0003.mdmp
10/31/07 15:28:04, ACTION, aspnet_wp.exe, Watson Invoke: No
10/31/07 15:29:31, ERROR , SQLDUMPER_UNKNOWN_APP.EXE, AdjustTokenPrivileges () failed (00000514)
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Input parameters: 4 supplied
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ProcessID = 2160
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ThreadId = 0
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Flags = 0x0
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDumpFlags = 0x0
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, SqlInfoPtr = 0x07E3356C
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, DumpDir = <NULL>
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExceptionRecordPtr = 0x00000000
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ContextPtr = 0x00000000
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExtraFile = <NULL>
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, InstanceName = <NULL>
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ServiceName = <NULL>
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 11 not used
10/31/07 15:29:31, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 15 not used
10/31/07 15:29:34, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 7 not used
10/31/07 15:29:34, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDump completed: C:Program FilesMicrosoft SQL ServerMSSQL.4Reporting ServicesLogFilesSQLDmpr0004.mdmp
10/31/07 15:29:34, ACTION, aspnet_wp.exe, Watson Invoke: No
10/31/07 15:31:14, ERROR , SQLDUMPER_UNKNOWN_APP.EXE, AdjustTokenPrivileges () failed (00000514)
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Input parameters: 4 supplied
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ProcessID = 2160
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ThreadId = 0
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Flags = 0x0
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDumpFlags = 0x0
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, SqlInfoPtr = 0x07E340D4
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, DumpDir = <NULL>
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExceptionRecordPtr = 0x00000000
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ContextPtr = 0x00000000
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExtraFile = <NULL>
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, InstanceName = <NULL>
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ServiceName = <NULL>
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 11 not used
10/31/07 15:31:14, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 15 not used
10/31/07 15:31:17, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 7 not used
10/31/07 15:31:17, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDump completed: C:Program FilesMicrosoft SQL ServerMSSQL.4Reporting ServicesLogFilesSQLDmpr0005.mdmp
10/31/07 15:31:17, ACTION, aspnet_wp.exe, Watson Invoke: No
10/31/07 15:37:52, ERROR , SQLDUMPER_UNKNOWN_APP.EXE, AdjustTokenPrivileges () failed (00000514)
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Input parameters: 4 supplied
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ProcessID = 2160
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ThreadId = 0
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Flags = 0x0
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDumpFlags = 0x0
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, SqlInfoPtr = 0x07E34C3C
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, DumpDir = <NULL>
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExceptionRecordPtr = 0x00000000
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ContextPtr = 0x00000000
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExtraFile = <NULL>
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, InstanceName = <NULL>
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ServiceName = <NULL>
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 11 not used
10/31/07 15:37:52, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 15 not used
10/31/07 15:37:54, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 7 not used
10/31/07 15:37:54, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDump completed: C:Program FilesMicrosoft SQL ServerMSSQL.4Reporting ServicesLogFilesSQLDmpr0006.mdmp
10/31/07 15:37:54, ACTION, aspnet_wp.exe, Watson Invoke: No
11/01/07 09:37:01, ERROR , SQLDUMPER_UNKNOWN_APP.EXE, AdjustTokenPrivileges () failed (00000514)
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Input parameters: 4 supplied
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ProcessID = 260
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ThreadId = 0
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Flags = 0x0
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDumpFlags = 0x0
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, SqlInfoPtr = 0x47405860
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, DumpDir = <NULL>
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExceptionRecordPtr = 0x00000000
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ContextPtr = 0x00000000
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ExtraFile = <NULL>
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, InstanceName = <NULL>
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, ServiceName = <NULL>
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 11 not used
11/01/07 09:37:01, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 15 not used
11/01/07 09:37:04, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, Callback type 7 not used
11/01/07 09:37:04, ACTION, SQLDUMPER_UNKNOWN_APP.EXE, MiniDump completed: C:Program FilesMicrosoft SQL ServerMSSQL.4Reporting ServicesLogFilesSQLDmpr0007.mdmp
11/01/07 09:37:04, ACTION, aspnet_wp.exe, Watson Invoke: No

View 6 Replies View Related

Tune Procedure !!!!!!!!!!!!!!!!! Urgent

Apr 18, 2002

How can l trim the code and make the procedure run faster ???????????????

CREATE Procedure Disbursements_Cats
(@startdate datetime,@enddate datetime)
As
Begin
SELECT Transaction_Record.loan_No AS loan_no,
Transaction_Record.transaction_Date AS Transaction_Date,
Transaction_Record.transaction_type AS Transaction_type,
Transaction_Record.transaction_Amount AS Transaction_Amount,

Product.product AS Product,
Product_Type.product_Type AS product_type,
Product_Type.loan_Type AS Loan_type,

Customer.first_name AS first_name,
Customer.initials AS initials,
Customer.second_name AS Second_Name,
Customer.surname AS surname,
Customer_identification.idno AS ID_No,

Bank.Bank_name AS Bank_Name,
Bank_detail.Account_no AS Account,
Bank_detail.Branch AS Branch

FROM Transaction_Record CROSS JOIN
Bank_detail CROSS JOIN Bank CROSS JOIN
Customer CROSS JOIN Product CROSS JOIN
Loan_Type CROSS JOIN Product_Type CROSS JOIN Customer_identification
End;
GO

View 1 Replies View Related

How To Tune Particular Store Procedure

May 12, 2008

Hello,

i need to tune some of my store procedures.

can any one help me how it's possible to tune particular store procedures?

Thanks
Prashant Hirani

View 3 Replies View Related

Creating Stored Procedure To Send Email To Multiple Users

Sep 20, 2007

Hi Everybody,

I am trying to setup a stored procedure that runs through a Reminders table and sends an email to users based on DateSent field being smaller than todays date. I have already setup the stored procedure to send the email, just having trouble looping through the recordset.




Code Snippet


CREATE PROCEDURE [dbo].[hrDB_SendEmail]

AS

BEGIN


DECLARE @FirstName nvarchar(256),

@LastName nvarchar(256),

@To nvarchar(256),

@ToMgr nvarchar(256),

@Subject nvarchar(256),

@Msg nvarchar(256),

@DateToSend datetime,

@Sent nvarchar(256),

@ReminderID int,

@RowCount int,

@Today datetime,

@Result nvarchar(256)

-- Get the reminders to send


SELECT

@ReminderID = r.intReminderID,

@DateToSend = r.datDateToSend,

@FirstName = e.txtFirstName,

@LastName = e.txtLastName,

@To = e.txtEmail,

@Subject = t.txtReminderSubject,

@Sent = r.txtSent

FROM


(auto_reminders r INNER JOIN employee e ON r.intEmployeeID = e.intEmployeeID) INNER JOIN ref_reminders t ON r.intReminderType = t.intReminderTempID

WHERE


(((r.datDateToSend)<20/12/09) AND

((r.txtSent)='False'))

-- Send the Emails


WHILE(LEN(@To) > 0)

BEGIN


EXEC @Result = sp_send_cdosysmail @To, @ToMgr, @Subject, @Msg

END

-- Mark the records as sent

IF @Result = 'sp_OAGetErrorInfo'


BEGIN


SELECT @Sent = 'Error'

END
ELSE


BEGIN


SELECT @Sent = 'True'

END
UPDATE auto_reminders

SET


auto_reminders.txtSent = @Sent, auto_reminders.datDateSent = @Today

WHERE


intReminderID = @ReminderID

END

GO







From the code you can probably tell I am new to writing stored procedures, so I apologise for any obvious errors. My major problems are :-


how to loop through each record

how to get todays date

whether the struture of the procedure is correct
Also, if you think there is an easier way or a better method, please suggest it. I am open to any suggestions you may have,

Thanks in advance
Ben

View 1 Replies View Related

Performance Of Views Accessed By Multiple SPIDs?

Jul 23, 2005

I wonder if anyone has any hard fact based pro or contra, especially onperformance, about having views as opposed to tables when the object isbeing accessed for read only by multiple sessions/users/spids. I amparticularly concerned about the multiple instantiations of the view.Relevant thoughts on this are much appreciated.Thanks,Caveman

View 1 Replies View Related

SSIS Clustered, Accessed By Multiple Instances

Feb 8, 2007

Hi,

I have a clustered environment which has many instances in it. I have modified the xml file to allow several instances to use ssis. Everything works great when the instances are on the same node as the clustered ssis. However if they are on different nodes there seems to be an aunthentication problem and it loses my credentials. For some reason it tries to use Anonymous Logon instead. Here is the full error:



The SQL server specified in SSIS service configuration is not present or is not available. This might occur when there is no default instance of SQL Server on the computer. For more information, see the topic "Configuring the Integration Services Service" in Server 2005 Books Online.

Login failed for user 'NT AUTHORITYANONYMOUS LOGON'. (MsDtsSrvr)



I would appreciate anyones help on this problem.

Thanks,

Adam

View 3 Replies View Related

Transact SQL :: Multiple Comma Separated Input For A Procedure

Jul 14, 2015

The Input parameters will be supplied like below for a procedure.

DECLARE @Subject NVARCHAR(100) = 'Math, Physics, Science'
      ,@ClassNumber NVARCHAR(MAX) = '102,103|415,206|712,876'
/*

I need to select subject with classnumber's supplied from the input screen and output a result like this.Let's say I have a temporary table dbo.TableA

--For  Math
INSERT INTO dbo.TableA
SELECT @Subject FROM Class
WHERE @ClassNumber in (102,103)

[code]....

View 6 Replies View Related

Transact SQL :: Stored Procedure To Return Multiple Records

Oct 21, 2015

I am looking out for sample  stored procedures returning multiple records

Example: GetOrderDetailsByOrderId

The above stored procedure should take orderId as parameter and should return the the order details along mutiple line item details.

View 4 Replies View Related

Permissions For Objects Accessed Through A Stored Procedure.

Apr 24, 2008


While trying to execute a stored procedure I am getting error that 'SELECT permission denied on table .......' The DBA has given execute permission for the sp and still the same error. What needs to be done. When permissions are given through the SP it implies that the objects are given permissions ?

Putting in db_datareader group will give permission to read from all tables across all the databases in the server. We want that the user should be able to read data from only those tables called in the sp. Normally in SQL 2000 we used to give EXECUTE permissions to the sp only. This in turn would be enough for that user to get data while executing the sp.

View 5 Replies View Related

Transact SQL :: How To Make Procedure Work For Multiple Values In Parameter

Jun 7, 2015

Below is the stored procedure i have it works fine if i have 1 value passed to @invited_by but i want to modify but i want this code to be working for multiple inputs .Lets say if i do

exec [dbo].[sp_GetInvitationStatusTest] 'Test1 . I get the desired output but i want this procedure to work for
exec [dbo].[sp_GetInvitationStatusTest] 'Test1,Test2'.
USE [merck_acronyms]
GO

[code]....

View 2 Replies View Related

Transact SQL :: Looping Through Multiple Servers And Databases In Stored Procedure

Aug 27, 2015

I am doing some administrative tasks and need to collect some principals information from multiple instances and user databases.

I have table "dbo.instances" with list of instances. 
I have databases from "sys.databases". 

How can I execute the query to get principals information from "sys.database_principals" on each remote instance and database. I know that can use cursor, but not sure how to do this with multiple servers and databases.

View 3 Replies View Related

Stored Procedure Performance Degrading Dramatically When Accessed Through ADO.NET

Oct 2, 2007

Hi

I am having a problem with a particular stored procedure in a database application and I have ran out of ideas as to what is the cause. When calling this stored procedure from a .Net application it typically returns results in about 0.2 seconds. 24 hours after it's creation, the procedure takes over 40 seconds to return the same results to the application. However if I call the procedure via Management Studio or Query Analyzer, the performance remains consistently fast.

It's a fairly complicated query making use of the following features:


FOR XML EXPLICIT

The ROW_NUMBER function

Input Parameters

The procedure is replicated, along with the tables that it references
The calling application is using ExecuteXMLReader to retrieve the results.

To fix the problem, I can simply run an ALTER PROCEDURE statement (without changing any of the contents of the stored procedure). However, by the next morning, the problem will have reoccurred.

Can anyone shed any light on why this is happening?

Phil

View 9 Replies View Related

Visual Source Safe Data Cannot Be Accessed Through SQL CLR Stored Procedure

May 15, 2008

The goal is to address visual source safe database on the network. We have the srcsafe.ini in the network as \ipaddrsrcsafe.ini. Now I create a new VSSDatabase object and call its OpenDb. Well for simple consle app or winform it is ok. But I was running it under Sql server Stored Procedure. It failed for I cannot access the source safe path throgh the COM object.

I know it is because of Windows identity. So I add the following code before I want to open the database, changing the to the WindowsIdentity:
WindowsIdentity impersonId = SqlContext.WindowsIdentity;
WindowsImpersonationContext orgCtx = null;
try
{
orgCtx = impersonId.Impersonate();
VSS_Database = new MVSI.VSSDatabase();
// VSS_Database.ImpersonateCaller = true;
VSS_Database.Open(Path, UserName, PassWord);
}
catch (Exception err)
{

orgCtx.Undo();
throw err;
}
finally
{
orgCtx.Undo();
}


Without the commented line "// VSS_Database.ImpersonateCaller = true", this does not work at all. It just behave like no changes to the windows identity.
However if I add this code, well, OpenDb will result in a No-response query. The Sql server is running the query with no responses.
Have you ever met that before? I am really frustrated. Thanks

View 3 Replies View Related

Stored Procedure To Get All Users Or All Users Of A Specific Country

Apr 30, 2008

hi alli've got two tables called "webusers" (id, name, fk_country) and "countries" (id, name)
at the meantime, i've a search-page where i can fill a form to search users. in the dropdown to select the country i included an option which is called "all countries".
now the problem is: how can i make a stored procedure that makes a restriction to the fk_country depending on the submitted fk_country parameter?it should be something like
SELECT * FROM webusers(if @fk_country > 0, which is the value for "all countries"){    WHERE fk_country = @fk_country}
who has an idea how to solve this problem?

View 9 Replies View Related

Where To Store Multiple Connectionstings For Multiple Users?

Oct 26, 2006



We have an application where users log in and set up a ConnectionString based on the login-info. As to now, we have used

Application.Contents("conn") = (strConnectionString)

in Global.asax.vb (Application_Start section) and then in the in the webforms we use

Dim con As New SqlClient.SqlConnection
con = New SqlClient.SqlConnection(Application("conn"))
con.Open()
......
......
con.close()

(Each user has their own sql database that they connect to using the same scripts.)

The question is: When many users are logged on at the same time, will the use of Application.Contents be a safe way to connect to each users own database or is there a possibility that users suddenly will try to establish a connection to a database that is not their own?

Scenario: User1 logs in at 10:00 and establish a connection to his own database. At 10:05 User2 logs on and establish a connection to his database since Global.asax.vb is run again. Will User1 now use User2's connection so that he is actually woking on User2's database?

Is there a better/safer way to do this connection in Global.asax.vb ?

Help much appreciated!!!!

View 8 Replies View Related

SQL Server 2014 :: Error Running Stored Procedure From SSIS Runs Fine In SSMS?

Mar 23, 2015

I have simple query which creates tables by passing database name as parameter from a parameter table .

SP1 --> creates databases and calls SP2--> which creates tables . I can run it fine via SSMS but when I run it using SSIS it fails with below error .The issue gets more interesting when it fails randomly on some database creation and some creates just fine .

Note** I am not passing any database of name '20'

Exception handler error :

ERROR :: 615 :: Could not find database ID 20, name '20'. The database may be offline. Wait a few minutes and try again. ---------------------------------------------------------------------------------------------------- SPID: 111 Origin: SQL Stored Procedure (SP1) ---------------------------------------------------------------------------------------------------- Could not find database ID 20, name '20'. The database may be offline. Wait a few minutes and try again. ----------------------------------------------------------------------------------------------------

Error in SSIS

[Execute SQL Task] Error: Executing the query "EXEC SP1" failed with the following error: "Error severity levels greater than 18 can only be specified by members of the sysadmin role, using the WITH LOG option.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.I have sysadmin permission .

View 6 Replies View Related

Transact SQL :: Search For Users By Either Their Name Or Nickname

Oct 14, 2015

I am using a web service to search for users by either their name or their nickname. Users can type the persons name into a dot net text box that has a Autocomplete extender - which means it returns a list of user with each keystroke.

This works fine if I just search for a name.

select r.fname +' ' + r.lname
from users u
join log l
on l.riderid = u.riderid

where fname +' '+ lname like @item +'%'
group by l.fname , r.lname, nicknamellame

So if I am searching for Dan Brown When I enter a D I get all users whose name starts with D, A reduces the list to those that start with Da until you get a small enough list to find Dan Brown. This works - what I would like to allow is if they entered the users nickname (another column in the users table) it would also include those options: So, if Dan's nickname is DannyBoy typing that in would return the nickname.

select r.fname +' ' + r.lname
, nickname
from users u
join log m
on l.riderid = u.riderid
where (fname +' '+ lname like @item +'%')
or (nickname like @item + '%')
group by r.fname , r.lname, r.nickname
having max(l.[date]) >= '2014-01-01'

This does not work

View 4 Replies View Related

Transact SQL :: Loop - How To Get Data For Each Of Active Users

Jun 9, 2015

My insert statement for #Data - I only need to process each @EmployeeID one time, which is why I thought a loop would be sufficient, but I let this process run for 2 hrs and it still had not completed, so I feel I must have set-up something incorrectly!

This is my syntax, I am creating a table of active users, then wanting to get data for each of those active users.  But only get the data for each active user 1 time.

Declare @EmployeeID varchar(50)
CREATE TABLE #ActiveUsers
(
ID INT IDENTITY NOT NULL
,EmployeeID varchar(50)
,processed int
)
Create Table #Data

[Code] ....

View 5 Replies View Related

Transact SQL :: Script To Disconnect All Users Except One From Two Databases

Aug 20, 2015

I need a script to kill existing sessions on [db1] and [db2] except sessions from [user1]. I have a script like this now:

USE master
GO
DECLARE @kill varchar(8000) = '';
SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), spid) + ';'
FROM master..sysprocesses
WHERE dbid = db_id('db1)
EXEC(@kill);

I just need to extend to run on db2 and don't kill sessions from user1

View 3 Replies View Related

Transact SQL :: Number Of Distinct Users In Last 3 / 6 / 9 / 12 Months

Aug 26, 2015

I have table A(year int, month int, user varchar(20)), and I am trying to write a view that would show number of distinct users in the last 3 months, last 6 months, last 9 months and last 12 months(all from the most recent year/month) in following format:

3 months     6 months     9 months     12  months

number of distinct users        x                  y                  z                      w

View 20 Replies View Related

Transact SQL :: Query To Convert Single Row Multiple Columns To Multiple Rows

Apr 21, 2015

I have a table with single row like below

 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Column0 | Column1 | Column2 | Column3 | Column4|
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Value0    | Value1    | Value2    | Value3    |  Value4  |

Am looking for a query to convert above table data to multiple rows having column name and its value in each row as shown below

_ _ _ _ _ _ _ _
Column0 | Value0
 _ _ _ _ _ _ _ _
Column1 | Value1
 _ _ _ _ _ _ _ _
Column2 | Value2
 _ _ _ _ _ _ _ _
Column3 | Value3
 _ _ _ _ _ _ _ _
Column4 | Value4
 _ _ _ _ _ _ _ _

View 6 Replies View Related

Transact SQL :: Create Email Report Which Gives Result Of Multiple Results From Multiple Databases In Table Format

Jul 24, 2015

I'm trying to create an email report which gives a result of multiple results from multiple databases in a table format bt I'm trying to find out if there is a simple format I can use.Here is what I've done so far but I'm having troble getting into html and also with the database column:

EXEC msdb.dbo.sp_send_dbmail
@subject
= 'Job Summary', 
@profile_name  =
'SQL SMTP',
   
[code]....

View 3 Replies View Related

Transact SQL :: Database Audit Specification On Specific Users

Mar 30, 2015

Currently I am using SQL server 2012 and would like to implement database audit specification on specific users in my database. These are the users in my database name Payroll :-

PayrollAndy.Bred - db_owner
PayrollArpit.Shah - db_owner
Payrollwebapp - db_datareader, db_datawriter, EXECUTE
web_payroll - db_datareader, db_datawriter, EXECUTE

In my database audit specification settings, I would like to capture any SELECT,UPDATE,DELETE and EXECUTE command for users PayrollAndy.Bred & PayrollArpit.Shah only since they owned db_owner access. However, I am unable to capture any single command from both users. I do not want to put 'Principal' as public since I just want to capture both users activity.

Is it I miss out anything? Is it because of windows login account?

View 2 Replies View Related

Transact SQL :: To Show Multiple Column In Multiple Rows

Aug 14, 2015

I have the following  database structure

Stock        Depth41     Depth12    Depth34
AAA            1              2              1
BBB             2            2               4

How can I show  Each Depth column as seperate row

AAA          1
AAA          2
AAA          1  as follows

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved