IdnCol ColumnA ColumnB ColumnC ColumnD 1 CC DD EE FF 2 DD GG HH JJ 3 HH JJ KK HH
How I can check for the repeated value in the column. for example in the 3rd record, in columnA and ColumnD the value HH is repeated so is there a way to find if there are values repeated in any of the columnA ColumnB ColumnC ColumnD.
Why this SQL procedure gives contiguous repeated records ( 3 or 4 times ) ?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ALTER PROCEDURE GetProductsOnPromotInDep (@DepartmentID INT) AS SELECT Product.ProductID, Title FROM Product INNER JOIN (ProductCategory INNER JOIN (Category INNER JOIN Department ON Department.DepartmentID = Category.DepartmentID) ON ProductCategory.CategoryID = Category.CategoryID) ON Product.ProductID = ProductCategory.ProductID WHERE Category.DepartmentID = @DepartmentID AND ProductCategory.CategoryID = Category.CategoryID AND Product.ProductID = ProductCategory.ProductID AND Product.OnPromotion = 1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If I have a student table with 3 columns ID, FirstName and LastName ID- FirstName -LastName ------------------------- 1 Tom Hanks 2 Jerry Thomas
and I have a subject table with two columns StudentID and Subject. StudentID is a foreign key to the student table. StudentID - Subject ------------------------ 1 History 1 Biology 2 History
If my query is select distinct student.id, student.fname, student.lname, student.subject from student left outer join subject on student.id = subject.studentid
then I get 1 Tom Hanks History 1 Tom Hanks Biology.
Is there a way I could get 1 Tom Hanks History null null null Biology
For the below mentioned query their is repetition of rows with the same data.
SELECT srs.prod_area as PA, srs.art as ArtNo, b.adsc_unicode as ArtName, cast(case when a.unit <> '2' then c.avsx/10 else c.avsx/1000 end as integer(2)) as AwsMHS, cast(srs.estimate/10 as integer(1)) as AwsSRSThisWeek,
I am beginner on using SQL. How can I select the repeated rows (five or more times) on a table which have the same ID's but different updated date. I do not need to group all the rows with the same ID,s but rows which are repeated many times according to the required reports needed.
Below are some information regarding tables and views:
Hi I have created a Percent Log Used Alert with a threshold of 85% and am getting e-mailed with Database Mail, the problem is that I continue to get e-mailed repeatedly with the same e-mail until I disable the Alert. Is there any way to have it just e-mail it once?
I have rows coming from the db including: Contract Number, Contract Name, owner and Actions associated with each contract.
SQL statement brings back: Contract Number Contract Name Sales Owner Action 1234 123453 $50 Neil x 1234 123453 $50 Bob y 534232 5464634211 $30 Harry z
The problem is that each contract can have multiple actions associated with it... There ideal output would be:
Contract Number Contract Name Sales Owner Action 1234 123453 $50 Neil x Bob y 534232 5464634211 $30 Harry z
Total: $80
Basically I need to hide and not include repeated items based on a contract number... one idea I had was creating a group based on contract number and then display info in the header and then only owner and actions in the detail section.. The problem is Totals... how can I can it to avoid count the duplicated values..
I am developing a system for my uni course and I am stuck a little problem...
Basically its all about lecturers, students modules etc - A student has many modules, a module has manu students, a lecturer has many modules and a module has many lecturers.
I am trying to get a list of lecturers that run modules associated with a particular student. I am able to get a list of the appropriate lecturers, but some lecturers are repeated because they teach more than one module that the student is associated with.
How can I stop the repeats?
Heres my sql select code in my cs file:
string sqlDisplayLec = "SELECT * FROM student_module sm, lecturer_module lm, users u WHERE sm.user_id=" + myUserid + "" + " AND lm.module_id = sm.module_id " + " AND u.user_id = lm.user_id "; SqlCommand sqlc2 = new SqlCommand(sqlDisplayLec,sqlConnection); sqlConnection.Open(); lecturersDG.DataSource = sqlc2.ExecuteReader(CommandBehavior.CloseConnection); lecturersDG.DataBind();
And here is a pic of my Data Model: Data Model Screenshot
I am running a query on multiple tables and the data I get back consists of several repeated rows but with one column different. I want to take out those repeated rows and for the column that is different join that data and separate it by a comma. Can this be done?
Ex. Cindy Lair 111 Drury Circle Harrisburg Pennsylvania 717 Cindy Lair 111 Drury Circle Harrisburg Pennsylvania 610 Cindy Lair 111 Drury Circle Harrisburg Pennsylvania 310
So i would like this data to come up as: Cindy Lair 111 Drury Circle Harrisburg Pennsylvania 717,610,310
In the web site that I am building ( in C# language ), a hypothetic customer who would buy something would be redirected to a Secure payments company where he would make the payment and then the company would send back to my web site, information about this transaction.
My program would then save this info in a Microsoft SQL database. The problem is that this company uses to send the same info several times repeatedly and I do not want to store the same info more than once.
So I want a SQL procedure where it takes the invoice number of the customer ( contained in its string of info ) and looks inside a table to see if it was already stored there. If it is there ( or not ), it would return a value, which could be false/true or 0/1 so my program could use this value to save a new info or not and then activate ( or not ) some related tasks.
I am still learning SQL and I tried the below procedure but it is not working. Which alternative procedure could solve the problem ?
~~~~~~~~~~~~~~~~~~~~~~~~~ CREATE PROCEDURE VerifyIfInvoiceExists (@Invoice VARCHAR(50)) AS SELECT COUNT(*) FROM IPN_received WHERE Invoice = @Invoice ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I'm using the following query to look in a log file and show somestatistics. It counts the total number of views and the total numberof unique users who have viewed a particular item (the "id" and"title" fields are associated with the item).SELECT title, COUNT(id) AS NumberViews, COUNT(DISTINCT UID) ASNumberUniqueUsers, Type, idFROM ActivityLogWHERE dtTime >= 'Nov 1 2004 12:00AM' AND DtTime <= 'Nov 1 200512:00AM'GROUP BY Title, Type, hdnIdORDER BY TopViewed descThis works fine on SQL Server 2000 (our development machine), but onSQL Server 7 (our production machine), the title column has the samevalue for every row. The other columns show the correct values.If I remove the "ORDER BY" clause, then it works fine. If I removethe "COUNT(DISTINCT UID)" column, it works fine. If I totally removethe WHERE clause, it works fine.Any ideas? It seems like a bug since it works fine on sql2k. I'vetried adding OPTION (MAXDOP 1) to the end of the query, but thatdidn't help.We're using SQL Server 7.0 sp1, and my boss doesn't want to riskupgrading to sp4 because it might screw up all of our otherapplications. I looked through all of the sp2 through sp4 bug fixes,and I didn't see anything specifically mentioning this.Thanks.
I am using the query below to retrieve these results: You can see that the results are repeated, once for DATIF = 1 and then again for DATIF = 2. In this case does not matter if the results appear close to DATIF 1 or DATIF 2. Take in care that I can not know how may extradates or Extrasums are attached to each Account.
Is there any way to avoid these repeated rows? Thanks in advance, Aldo.
ExtraSums.SUF FROM EXTRADATES AS ExtraDates LEFT OUTER JOIN EXTRADATENAMES AS ExtraDateNames ON ExtraDates.DATFID = ExtraDateNames.DATFID RIGHT OUTER JOIN ACCOUNTS AS Accounts ON ExtraDates.KEF = Accounts.ACCOUNTKEY LEFT OUTER JOIN EXTRASUMS AS ExtraSums LEFT OUTER JOIN EXTRASUMNAMES AS ExtraSumNames ON ExtraSums.SUFID = ExtraSumNames.SUFID ON Accounts.ACCOUNTKEY = ExtraSums.KEF LEFT OUTER JOIN EXTRANOTENAMES RIGHT OUTER JOIN EXTRANOTES ON EXTRANOTENAMES.NOTEID = EXTRANOTES.NOTEID ON Accounts.ACCOUNTKEY = EXTRANOTES.KEF WHERE Accounts.SORTGROUP BETWEEN 0 AND 999999999 AND Accounts.ACCOUNTKEY BETWEEN '123456' AND '123456'
I have hundreds of these errors saying 'Login failed for user 'Reporting' The user is not associated with a trusted SQL Server connection [CLIENT: ip address]
The ip address is that of the server that sql server is installed on.
Looking in my log file, all looks good until I get to Service Broker manager has started, then I get Error: 18452, Severity: 14 State: 1 then these two lines repeat about every minute, for the last 3 days!
I think I must have just missed a tick box somewhere, but where?
I have been into one of the databases, and input and checked data, both via an application I wrote and SQL Server Management Studio.
I am also having trouble connecting using my application to connect to the database, I can only connect if I use a Windows administrator account (this SQL Server 2005 running on a Windows 2003 Server, with the app on PC running Windows 2000)
I have a matrix report with one row group and one dynamic column group. My issue is that I want to see the column group to be appeared only on the first page of the report not on every next page, because I am going to finally export the report to Excel spreedsheet so I don't want the column to be repeated in the middle of the records.
I am fairly new to SQL Server 2005 and before now, I have only had to restore databases, and connect to tables via ODBC connection in a reference (read only) setup. Today, I have a very small project to set up using the server.
I have a userlogon.csv file that the network stores on a file server in a hidden share logon$. It has 4 columns, UserID, Computer, Date, Time.
I was able to create a database called UserLogon and import the file as it was today. I want to create a scheduled update so the server would go to this file perhaps 4 times a day (or more) and grab any new logins that have appended itself to this CSV file.
So, as a newbie with a 1,900 page SQL Server 2005 unleashed manual at my side, could someone outline what the steps are in general I should follow to set this up?
I have the process laid out in my mind, but I don't know how to translate in into a scheduled task of the SQL Server :
1. Create DB and import the table (done) 2. create a stored procedure that connects to the CSV file and evaluates date and time stamps then appends any new records into the SQL db table. (appending records would be achieved by using the INSERT and WHERE statements?) 3. Schedule a job to perform this task on a routine basis.
It appears that the file connection portion of this set up is defined outside the evaluation and append record procedure? (not in the same stored procedure). Perhaps I tie the whole process together using the Job Manager, selecting the file settings, and then the stored procedure to be performed on the file.?
I hope I have been descriptive enough to ask if someone could outline the modules/features/processes involved so I can read up on them and figure them out using the book.
Ihave a table With A Culomn That Is NOT Unique And Repeat Many Tims BUT I want To Have a Select Command That Filter Repeated Value And Show Only One of rows Whith Same Data
In the web site that I am building ( in C# language ), a hypothetic customer who would buy something would then be redirected to a Secure payments company where he would make the payment and then the company would send back to my web site, information about this transaction.
My program would then save this info in a Microsoft SQL database. The problem is that this company uses to send the same info several times repeatedly and I do not want to store the same info more than once.
So I want a SQL procedure where it takes the invoice number of the customer ( contained in its string of info ) and looks inside a table to see if it was already stored there. If it is there ( or not ), it would return a value, which could be false/true or 0/1 so my program could use this value to save a new info or not and then activate ( or not ) some related tasks.
I am still learning SQL and I tried the below procedure but it is not working. Which alternative procedure could solve the problem ?
~~~~~~~~~~~~~~~~~~~~~~~~~ CREATE PROCEDURE VerifyIfInvoiceExists (@Invoice VARCHAR(50)) AS SELECT COUNT(*) FROM IPN_received WHERE Invoice = @Invoice ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
INSERT #Visits (OpportunityID, ActivityID, FirstVisit, ScheduledEnd) SELECT 1, 1001, '2014-08-17', '2014-08-17 12:00:00.000' UNION ALL SELECT 1, 1002, '2014-08-17', '2014-08-17 17:04:13.000' UNION ALL SELECT 2, 1003, '2014-08-18', '2014-08-18 20:39:56.000' UNION ALL
Basically I'd like to mark the first Activity for each OpportunityID as a First Visit if its ScheduledEnd falls on the same day as the FirstVisit, and otherwise mark it as a Repeat Visit.
I have this so far, but it doesn't pick up on that the ScheduledEnd needs to be on the same day as the FirstVisit date to count as a first visit:
SELECT*, CASE MIN(ScheduledEnd) OVER (PARTITION BY FirstVisit) WHEN ScheduledEnd THEN 1 ELSE 0 END AS isFirstVisit, CASE MIN(ScheduledEnd) OVER (PARTITION BY FirstVisit) WHEN ScheduledEnd THEN 0 ELSE 1 END AS isRepeatVisit FROM#Visits
How to normalization would be use 3 tables ,one for tags_id and tags, and another relating the tags_id to ID from the table above...but how does the code already know there is a tag called repeating?
OS- Windows server 2012 SQL - Windows SQL 2012 R2 Sharepoint 2010 SP2
SQL has DB restored from earlier server. DB is quiet large in size because used with sharepoint.
Following steps have been followed on this restored DB -
Maintenance Plan Rebuild-Reorganize the indexes Update Statistics
After above steps, query on Sharepoint table found performant. But after some delay/idol time(overnight) on server. Query takes much more(20X) time to execute. On running execution plans observed that some warnings are seen on columns which are primary keys.
Columns with no statistics 'AllDocs.tp_DocID'
When Update statistics is executed again in SQL management studio above issue is again seen resolved, but came again after some delay.
Is there any SQL logs where can I find activities performed during overnight with SQL which make this issue to happen? This issue was not there on Win2k8 environment.
Presumably an easy question but every time I open a query file the SSMS requires me to login. Very frustrating. Cannot find a configuration option, properties attribute or other to turn this off. Can anyone adivse how I can set up SMSS to require a login at the beginning of the session and then not again for each saved query I open?
Hi All, Would appreciate some assistance with the attached, I'm using some fairly complicated recordsets (ASP VBScript) for a property search website, I have a page where a user selects search by County this in turn takes them to a page which lists all the towns in the county and number of live properties in each, I'm using 4 recordsets for this - 3 of which list the towns (townsA2I, townsJ2R & townsS2Z) the 4th is a Property Count, examples of the recordsets are below (using townsAtoI and LiveProperties -
TownsA2I
<% Dim TownA2I Dim TownA2I_numRows
Set TownA2I = Server.CreateObject("ADODB.Recordset") TownA2I.ActiveConnection = MM_recruta2_STRING TownA2I.Source = "SELECT towncountyID, Town, County FROM dbo.easytolettowncounty WHERE Town LIKE 'A%' AND County = '" + Replace(TownA2I__MMColParam, "'", "''") + "' OR Town LIKE 'B%' AND County = '" + Replace(TownA2I__MMColParam1, "'", "''") + "' OR Town LIKE 'C%' AND County = '" + Replace(TownA2I__MMColParam2, "'", "''") + "' OR Town LIKE 'D%' AND County = '" + Replace(TownA2I__MMColParam3, "'", "''") + "' OR Town LIKE 'E%' AND County = '" + Replace(TownA2I__MMColParam4, "'", "''") + "' OR Town LIKE 'F%' AND County = '" + Replace(TownA2I__MMColParam5, "'", "''") + "' OR Town LIKE 'G%' AND County = '" + Replace(TownA2I__MMColParam6, "'", "''") + "' OR Town LIKE 'H%' AND County = '" + Replace(TownA2I__MMColParam7, "'", "''") + "' OR Town LIKE 'I%' AND County = '" + Replace(TownA2I__MMColParam8, "'", "''") + "' ORDER BY Town ASC" TownA2I.CursorType = 0 TownA2I.CursorLocation = 2 TownA2I.LockType = 1 TownA2I.Open()
TownA2I_numRows = 0 %>
LiveProperties
<% Dim LiveProperties Dim LiveProperties_numRows
Sub sLivePropertyCount(vLocation) vCount=0
Set LiveProperties = Server.CreateObject("ADODB.Recordset") LiveProperties.ActiveConnection = MM_recruta2_STRING LiveProperties.Source = "SELECT COUNT(PropertyID) As NumberofProperties, propertylive, propertylocation FROM dbo.easytoletproperty WHERE propertylive = 'y' AND propertylocation = " & vLocation & " GROUP BY propertylocation, propertylive" LiveProperties.CursorType = 0 LiveProperties.CursorLocation = 2 LiveProperties.LockType = 1 LiveProperties.Open()
LiveProperties.Close() Set LiveProperties = Nothing end sub
LiveProperties_numRows = 0 %>
I've tried following the tutorial here http://www.webthang.co.uk/tuts/tuts_dmx/rob9/rob9.asp but when i review the page i get the following error -
"Microsoft OLE DB Provider for SQL Server error '80040e14'
Invalid column name 'Barnet'.
/PropertiesbyTown1.asp, line 338 "
Where line 338"
Where line 338 is the "LiveProperties.Open()" of the above recordset, when i try to view bindings on this recordset Dreamweaver gives me the following errors -
"Column 'dbo.easytoletproperty.propertylive' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.
Column 'dbo.easytoletproperty.propertylocation' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause."
From what I've seen, the CheckSum_Agg function appears to returns 0 for even number of repeated values. If so, then what is the practical use of this function for implementing an aggregate checksum across a set of values?
For example, the following work as expected; it returns a non-zero checksum across (1) value or across (2) unequal values.
declare @t table ( ID int ); insert into @t ( ID ) values (-7077); select checksum_agg( ID ) from @t; ----------- -7077 declare @t table ( ID int ); insert into @t ( ID ) values (-7077), (-8112); select checksum_agg( ID ) from @t; ----------- 1035
However, the function appears to returns 0 for an even number of repeated values.
declare @t table ( ID int ); insert into @t ( ID ) values (-7077), (-7077); select checksum_agg( ID ) from @t; ----------- 0
It's not specific to -7077, for example:
declare @t table ( ID int ); insert into @t ( ID ) values (-997777), (-997777); select checksum_agg( ID ) from @t; ----------- 0
What's curious is that (3) repeated equal values will return a checksum > 0.
declare @t table ( ID int ); insert into @t ( ID ) values (-997777), (-997777), (-997777); select checksum_agg( ID ) from @t; ----------- -997777
But a set of (4) repeated equal values will return 0 again.
declare @t table ( ID int ); insert into @t ( ID ) values (-997777), (-997777), (-997777), (-997777); select checksum_agg( ID ) from @t; ----------- 0
Finally, a set of (2) uneuqal values repeated twice will return 0 again.
declare @t table ( ID int ); insert into @t ( ID ) values (-997777), (8112), (-997777), (8112); select checksum_agg( ID ) from @t; ----------- 0
It seems that there should be a solution for my situation, but for the life of me I can't seem to figure it out.
I need to compare two "like" tables, containing similar data. Tbl 1 is "BOOKED" (which is a snapshot of inventory) and tbl 2 is "CURRENT" (the live - working inventory table). If I write my query as follows the the subsequent result is "duplicate" data.
Code Block SELECT booked.item, booked.bin, booked.quantity, current.bin, current.quantity FROM BOOKED LEFT JOIN CURRENT ON booked.item = current.item
No matter what type of join I use, there is duplicate data displayed for each table. For example, if there are more bins in the BOOKED table that contain a certain product then the CURRENT table will repeat data and vica versa.
As follows:
Item Bin Quantity Bin Quantity
12345 A01 500 A01 7680
12345 B01 6 A01 7680
12345 C01 20 A01 7680
54321 G10 1032 E15 1163
54321 G10 1032 F20 523
54321 G10 1032 H30 750
98765 Z20 7000 Z20 8500
98765 Y15 2500 Y15 3000
98765 X10 1200 Y15 3000
What I would like to do is display Bin and Quantity only once and the repeating values as NULL or [BLANK]. Or, to display all of the bins from both tables and only the quantities from each table in relation to the bin found in that table, returning a "0" if no quantity exists.
This is what I'm after:
Item Bin Quantity Bin Quantity
12345 A01 500 A01 7680
12345 B01 6 B01 0
12345 C01 20 C01 0
54321 G10 1032 E15 1163
54321 F20 0 F20 523
54321 H30 0 H30 750
98765 Z20 7000 Z20 8500
98765 Y15 2500 Y15 3000
98765 X10 1200 X10 0
Is this possible? If so, how?
I also might add that it is ok for each table to contain multiple entries for any given item. This is basically being requested as an inventory variance report - inventory before physical count and immediatly after physical count - and will only be run once a year.
----------------------------------------------- Just thinking out loud here: What if I created three subqueries, the first containing only BOOKED information, the second containing only CURRENT information and the third being a UNION of both tables? Something like this:
Code Block SELECT q3.bin, q1.item, ISNULL(q1.quantity, 0) as QTY_BEFORE, ISNULL(q2.quantity, 0) as QTY_AFTER
FROM
(select item, bin, quantity from BOOKED)q1 Left Join
(select item, bin, quantity from CURRENT)q2 on q1.item = q2.item Left Join
(select bin, item from BOOKED UNION CURRENT)q3 on q1.item = q3.item
Order By q1.item
I don't know if I wrote the UNION statement correctly, but I will have to try this when I get back to work...