Hi I'm using a gridview to show a list of high scores in a c#.net page. The position of the score is not stored in the database, just the score, name and id. In the gridview however I would like to indicate the position of the scores, the SQL statement sorts the records by ascending scores so the are already in the correct order. Does anybody know how to include a counter in the SQL statement that I can refer to vai the gridview so that it is able to display it as the position? Thanks in advance for any help!
# 1 - You want a Multipage Hit Counter to keep track of the number of Hits each individual webpage gets in your website. # 2 - You also want to store the Webpage Hit Count Values into a SQL Database, using Stored Procedures.
Dim objCon As New SQLConnection("server=yourServerName;User id=idName;password=yourPassword;database=HitsCounter")
Dim cmd As SQLCommand = New SQLCommand("EXEC dbo.webcounter1", objCon)
objCon.Open()
Dim r as SQLDataReader
r = cmd.ExecuteReader()
r.read()
strcounter3.text = "Hits : " & r.item(0)
end sub
</script>
Also insert the following inside the body tags of webpage #1 <asp:Label id="strcounter3" font-size="X-Large" font-bold="True" bordercolor="Silver" width="300px" borderstyle="Inset" forecolor="Lime" visible="True" runat="server"></asp:Label>
Marked in Red webcounter1 is the Stored Procedures Name. ALso marked in<B> Red counter3 is the name of the Database. This is where you would make your changes inside the Webpages.
Use the following Stored Procedure with Webpage #1
CREATE PROCEDURE dbo.webcounter1 WITH RECOMPILE AS BEGIN SET NOCOUNT ON DECLARE @hits INT SELECT Hit FROM counter3 WHERE ID = 1 update counter3 set hit = hit + 1 EXEC sp_recompile counter3 END GO
The Database Table has 2 columns which consists of an ---ID & Hit Column -- The Table Name is (counter3) The best way to explain is by showing so posted below are Webpages 1 & 2 along with there Stored Procedures.
Dim objCon As New SQLConnection("server=yourServerName;User id=idName;password=yourPassword;database=HitsCounter")
Dim cmd As SQLCommand = New SQLCommand("EXEC dbo.webcounter2", objCon)
objCon.Open()
Dim r as SQLDataReader
r = cmd.ExecuteReader()
r.read()
strcounter3.text = "Hits : " & r.item(0)
end sub
</script>
Also insert the following inside the body tags of webpage #2 <asp:Label id="strcounter3" font-size="X-Large" font-bold="True" bordercolor="Silver" width="300px" borderstyle="Inset" forecolor="Lime" visible="True" runat="server"></asp:Label>
Use the following Stored Procedure with Webpage #2
CREATE PROCEDURE dbo.webcounter2 WITH RECOMPILE AS BEGIN SET NOCOUNT ON DECLARE @hits INT SELECT Hit FROM counter3 WHERE ID = 2 update counter3 set hit = hit + 1 EXEC sp_recompile counter3 END GO
Now this type of Hit Counter works fine to a point. Visiting Webpage #1 accumilates 1 Hit & Visiting Webpage #2 Accumilates 2 Hits. And each time there 's a revisit to these pages they acquire 2 Hits each. I'm Guessing the problem is in the Stored Procedure storing there values in Memory. If Someone can Help Figure Out how to fix this. This could be a nice Website Multipage Hit Counter. I can use some help Guys feel free to advise.
I'm trying to write a select that returns a result set with a counter added on. I want to do it without using an identity column or cursor. Something along the lines of select col1, max(col2)+1 from tab1. I get (as expected)
The sqlserv.exe takes too much CPU utilization on my SQL 2000 on W2K production machine. I am tring to use System Monitor to monitor the Thread/%process time with all Sqlservr instances, and then match the sqlservr instance number to the KPID in sysprocesses table to find out which user is causing the problem. but I can only see the instance number from Sqlservr0 to sqlservr99. From the table sysprocesses table, the KPID is all 3 or 4 digits number. Any one has any idea about this?
I am looking to create a incremental value based on the resulting insert that I am using. There already is another field being used as an identity field. I have a beginning value that I just want to add the row number to for the insert.
insert into lineitem select substring(group_id,4,len(ltrim(rtrim(group_id)))-3) as co_code, 0,0,(case when enddate < cast(month(getdate()) as varchar(10))+cast(day(getdate()) as varchar(10)) then 'Prior' else 'Current' end ), left(acct_type,2) as bene_type, convert(smalldatetime,left(ltrim(rtrim(eff_date)), 8)), 0,trans_amt,0,0,convert(smalldatetime,left(ltrim(r trim(sett_date)),8)), ltrim(rtrim(b.fname)) + ' ' + ltrim(rtrim(b.lname)) as payee,0,0,a.ssn,'Y',999+count(*), (case when isnull(b.location,'') = '' then '' else b.location end) as location from mbi_tran_temp a left join enrollees b on a.ssn = b.ssn and ltrim(rtrim(a.group_id)) = ltrim(rtrim(b.mbicode))
The '999+count(*)' is where I would like to have the incremental value.
It sound like a simple task to perform but I just can't seem to get it. I've built a search function on the site and after each search request, a log is kept of the search word and the date, so the table looks a little like this:
My client wants IN_PUNCH to be the first in punch of the day and the OUT_PUNCH to be the last out punch of the day based on the TransactionDate as it is showing in the desired results table for 07/29 and 07/30 (Changes are highlighted in Bold).
I tried using MIN and MAX at different areas but to no avail.Also, is there a way to add a counter at the end of each row so in case if there were two shifts in a day then it be a '1' for row 1 and a '2' for row 2?
WITH SampleData (PERSON,TRANSACTDATE, STARTDATE, END_DATE, IN_PUNCH,OUT_PUNCH,HOURS,PAYCODE,SHIFT_LABEL,DOW) AS ( SELECT 1234,'07/27/2015','07/27/2015','07/27/2015', '12:00','12:00','8', 'Hol', 'NULL', 'Monday' UNION ALL SELECT 1234,'07/28/2015','07/28/2015','07/28/2015', '08:00','','4.00', 'Absent', 'Batax 1st','Tuesday' UNION ALL SELECT 1234,'07/28/2015','07/28/2015','07/28/2015', '12:15','14:00','3.75', 'Regular', 'Batax 1st','Tuesday' UNION ALL
I need to count the days (24 hours)from the (GETDATE()),returning an integer in a table column, automatically, all the time , under the scene until after a specified number of days (usually 20 for example), the relevant table row is be automatically deleted, replaced by another insert (row) to start again and the process repeated many times.
I have a database which works automatically. The data need not to be queried or manipulated until the row is deleted automatically. I use SQL Server 2000.
Any ideas of doing this in a simple way ? Regards and thanks in advance.Yves.
this procedure resets the business day to one for every month. It works fine except for the month of October. any idea or suggestions?
DECLARE @i INT SET @i = 1 DECLARE @DateID INT, @DtTimeD DATETIME, @LASTDAY DATETIME DECLARE c CURSOR FOR -- -- LASTDAY is the last day of the month -- the counter will reset to 1 on the first of each month -- SELECT DateID, DtTimeD, DATEADD(dd, -DAY(DATEADD(m,1,DtTimeD)), DATEADD(m,1,DtTimeD)) 'LASTDAY' FROM D_DATE WHERE WkDayIn = 'Yes' AND HolidIn = 'No' OPEN c FETCH NEXT FROM c INTO @DateID, @DtTimeD, @LASTDAY WHILE @@FETCH_STATUS = 0 -- -- update the business day in D_DATE -- BEGIN UPDATE D_DATE SET BusDay = @i WHERE DateID = @DateID -- -- reset the counter to 1 if it's the last day of the month -- IF @DtTimeD = @LASTDAY SET @i = 1 ELSE SET @i = @i + 1 -- IF @@ROWCOUNT = 500 COMMIT -- FETCH NEXT FROM c INTO @DateID, @DtTimeD, @LASTDAY END CLOSE c DEALLOCATE c GO
I have a form that I turned off the nav buttons. I then create my own.The reason I do is that I cna then move the nav buttons any where I needto on the form.The only thing I can not figure out is on the default ones, it shows thetotal records. I can not figure out how to do this. The form is based ona table and when I add a record or delete a record I want to make ssurethe total displayed is correct.How can I display the total records, for the table, on the form on thefly?Does that make sense?Michael Charneym charney at dunlap hospital dot org*** Sent via Developersdex http://www.developersdex.com ***
While inserting data into a target table, I'm trying to populate a primary key ID field sequentially. For each record, the value of the primary key field needs to be incremented by one (a counter).
I've tried to use the RowCount transformation to store the values in a variable. I'm able to successfully do that; however, I don't know how to read or update the variable incrementally.
If someone knows how to perform this task, please let me know. I would greatly appreciate it.
I need some comments regarding my Hit Counter that I have created for my sites. Here is my case:
I have developed several websites which I host along with MS SQL server. I created a class that calls a stored procedure to add a count to the database field. The way that I am using it is that every page in the page_load event will call the class indicating which counter to use (i.e. LoginPage, HomePage, ProductPage, etc.). The class in turn will perform the database route to increment the counter. In the Store procedure before incrementing the counter, I first check to see if a record for the current date has been created, if not I add the record with a date stamp with all the different counter values as zero. I then will add 1 to the desired counter for the date.
Is this a good solution?
What I now want to do is create a page that allows the different website owners to access a page with the relevant page counters.
I'm a local admin on a SQL Server with dba permissions. I can view that SQL Server in System Monitor and I can create a performance log counter. When I try to start the counter, I get an error: --------------------------- Performance Logs and Alerts --------------------------- The SQLSever log or alert has not started. Refresh the log or alert list to view current status, or see the application event log for any errors. Some logs and alerts might require a few minutes to start, especially if they include many counters. --------------------------- OK ---------------------------
Is there anyway i can write down a query to get the sum of the counter with 2 minutes difference. I may take time slot between 9 AM to 10 AM so i should get the sum of the counter with 2 minutes gap in a single query.
Hi, can you add a counter inside a select statement to get a unique id line of the rows? In my forum i have a page that displays a users past posts in the forum, these are first sorted according to their topicID and then they are sorted after creation date. What i want is in the select statement is to create a counter to get a new numeric order. This is the normal way: SELECT id, post, comment, created FROM forum_posts WHERE (topicID = @topicID) ... some more where/order by statements This is what i want: DECLARE @tempCounter bigintSET @tempCounter = 0SELECT @tempCounter, id, post, comment, created FROM forum_posts WHERE (topicID = @topicID)... some more where/order by statements and at the end.. (SELECT @tempCounter = @tempCounter + 1) Anyone know if this can be done?
Using MSSQL (pre 2005): I have a Link table: int id (primary key/identity) varchar(50) linkName varchar(255) linkHref //some other stuff and my Hits table: int id (primary key/identity) int linkId (foreign key to Link) datetime dateCreated //some other stuff Hits gets an insert whenever a link is clicked. (All this works just fine) I'm trying to create a report that shows each link by its name and href, a counter and the last date each link was visited. What I currently have is an accurate listing for those that have been clicked on, but it does not show anything for links that haven't been clicked on. Any suggestions as to how I can modify the following SQL to return "0" and "never" (or DBNULL) if no entries are found in Hits that have the same id? Or do I have to do this in a couple queries? SELECT COUNT(h.id) as counter, MAX(h.dateCreated) as lastVisited, l.id as id, l.linkName as linkName, l.linkHref as linkHref FROM Link as l INNER JOIN Hits as h ON l.id=h.moduleId GROUP BY l.linkName, l.id, l.linkHref
I need to to have a table that has a counter field (used to generate an id code for a record). This is not the primary id for the field but just a counter to label a record in another table, similar to a registration code for an event. This is a sequential counter that will start 1 and go up on each new record inserted into other tables. What I want to do is be able to query this counter table to get the next valid number and increment the count for the next time. This is a multi user web app so needs to prevent duplicate use of same number.How best should this be handled? A transaction to query and update the field?
I have a table with fields name Days1, Days2, Days3 - I am trying to use a loop in conjunction with a counter to identify each of these fields - I can't quite get the correct syntax and it is driving me crazy!!!
Here's the proc:
WHILE @Counter < 4 BEGIN
SELECT @AppointmentsCount = COUNT(tbl_SurgerySlot.SurgerySlotKey) FROM tbl_SurgerySlot INNER JOIN tbl_SurgerySlotDescription ON tbl_SurgerySlot.PracticeCode = tbl_SurgerySlotDescription.PracticeCode AND tbl_SurgerySlot.Label = tbl_SurgerySlotDescription.Label LEFT OUTER JOIN tbl_Appointment ON tbl_SurgerySlot.SurgerySlotKey = tbl_Appointment.SurgerySlotKey AND tbl_SurgerySlot.ExtractDate = tbl_Appointment.ExtractDate WHERE (tbl_SurgerySlot.ExtractDate = @ExtractDate) AND (tbl_Appointment.AppointmentKey IS NULL) AND (tbl_SurgerySlot.StartTime > @DateFrom) AND (tbl_SurgerySlot.StartTime < @DateTo) AND (tbl_SurgerySlotDescription.IsBookable = 1)
SET @FieldName = 'Days' + CONVERT(VARCHAR(20),@Counter)
INSERT INTO tmp_Availability (@FieldName) VALUES (@AppointmentsCount)
SET @DateTo = DATEADD(Day,1,@DateTo)
--Increment the loop counter SET @Counter = @Counter + 1
When I run the above the follwoing message is displayed:
Server: Msg 208, Level 16, State 3, Line 36 Invalid object name 'tmp_Availability'.
Error Message "invalid column name on total_counter ". How to edit this query and make it work ?
SELECT salesman_code,user_group,user_name,trx_acc_amt,trx_date,trx_no,sh_code, salesman_code4,salesman_code5,salesman_code6, Sum(case when salesman_code4 is null then 0 else 1 end + case when salesman_code5 is null then 0 else 1 end + case when salesman_code6 is null then 0 else 1 end) as total_counter,
What exactly does the DatabasesTransactions/sec measure? The explain button says: "Number of transactions started for the database." Does this mean the number of transactions initiated during the time period or is it some kind of average of the number in progress.
The reason I am asking is that sometimes I see a spike in Transactions/sec. lasting about a half hour concurrent with high memory and CPU usage. Does this really mean that too many transactions are being started or is it a side effect of the machine being too busy to complete transactions thus leaving them pile up uncompleted.
It seems like it should be counting the number of BEGIN TRANSACTIONs statements (plus implicit ones) actually received during the time period, but I'm not having an easy time diagnosing this problem so I am trying to figure out what to rule out.
Let me get VERY specific. This site has 40+ pages Using VWD 2008 (Studio 2008) I have created in local IIS7 (129.0.0.2) http://cumc.lcl Navigation.master, Web.config and Web.sitemap alll are structured And all 40+ pages have been built. NOW I added (using VWD) a sql server database named pagedata.mdf With a table named: pages and fields: PageID - Primary Key (auto numbered) pagename - nchar(30) exmp Default hitcount - numeric(18,0) createdate - nchar(15) exmp 04/18/2008 updated - nchar(15) similar to createdate hitdate - nchar(15) similar to createdate bottom of each page is to show 99999 visitors and under that is to be Updated on mm/dd/yyyy On pageload should accomplish the following increment the hitcount field and save it and display it in HitLabel.text Set UpdateLabel.text to updated field Save the date the page was hit in hitdate field. (will only show when last hit)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub </script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <p align="center">This page is for various tests<br />and will NOT be site mapped.</p> <p align="center"></p> <p align="center">
Can this SqlDataSource be moved into Sub Page_load above? How do I extract, process and save the Hit and Date data for each individual page referenced by pagename field? <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStringsageConnect %>" SelectCommand="SELECT * FROM [main] WHERE ([pagename] = @pagename)"> <SelectParameters> <asp:QueryStringParameter Name="pagename" QueryStringField="thispage" Type="String" /> </SelectParameters> </asp:SqlDataSource> </p> <p align="center"> <asp:Label ID="HitLabel" runat="server"></asp:Label> Visitors<br /> Updated on <asp:Label ID="UpdateLabel" runat="server"></asp:Label> </p> </asp:Content>
I have a 64-bit SQL Server running on 64-bit OS having 12GB of RAM. The Server only hosts our Application database (its a 30 GB database). There are no major process running on it. Despite of this, the Avg Pagessec shows a count of 1500 and the Avg Page Faultsec shows 22000. Is there any specific reason as to why this is happening? The %idle time of the disk is 87%. Also there is no major load on the server. Do let me know if you need any other input.