.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

eliminate non-unique, with a twist

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :Sql Server

Here is sample data.

create table #list (
	item char(1)

insert into #list values ('A')
insert into #list values ('B')
insert into #list values ('C')
insert into #list values ('D')

select * from #list


Now, I do a self join where the items are not the same.

select lft.item + rght.item
from #list lft
join #list rght on lft.item != rght.item


But I want to also filter out repeating combos. For example, 'AB' is the same as 'BA'. So I want to return only one of these two.

In the end, the final result set should be,


View Complete Post

More Related Resource Links

Unique content within master page based on conditions met


 Hi all-

I would like to present users with unique content based on certain conditions being met as they land on the home page (default.aspx).  The condition logic will be in the VB code behind Page Load event. The content will go in a content placeholder as specificed from the master page. 

However, the content change wouldn't be something small (ie making a panel or label visible or not) but rather it will be different HTML,  Divs and databound gridview content.  The HTML content will be stored in the database.

Can someone point me in the right direction for best practices on how to accomplish this?


Unique ID throughout entire request



I am hoping somene here could advise me on a better solution to my present problem.  First a little background information on the application. 

I have a web application using the 3.5 framework.  The structure of this application is as follows: UI -> WebService   -> Business Layer -> DataAccess Layer.   What I want to accomplish is for every request (click on a link or button) have a unique identifer that follows this request through its entire lifecycle.  This unique identifer can be accessible anywhere within this request.  We use Response.Redirects which could easily be changed to Server.Transfers (although I do not want to do that) but  the problem lies with the web service calls.  Currently, a GUID is set in the ApplicationRequest.  This GUID checks for a guid value in the RawURL and if so, assigns this value to a HttpContext Item.  If not, HttpContext.Items gets a new one created.  However, this idea is wrong and will need to be revisisted.  The bigger problem is with the web service calls.  Without changing every web service method signature, and every call for that matter, is there a way of getting this GUID there.  I created a web method in every web service so that each time I instantiate a web service object in the UI, before calling any

Unique text value in databse column


Hi Everyone!

I know this is probably a very basic question but how do I keep a column's text values unique in SQL server (ie for a unique username)?  The column is not an integer it's varchar(50), and it's not the primary key but I could make it the primary key if recommended.

The front end could handle it;  where the user would enter text, it's validated, then a query is done to see if that username is available.  If so, then user can decide to choose it and an insert is done, if not they pick a new username and process repeats.  With this approach, the responsibility of keeping the value unique solely rests on the front end, nothing on the database side.

Is this the correct way to handle this? 

Thank you!


Windows 2000: Asynchronous Method Calls Eliminate the Wait for COM Clients and Servers


Windows 2000 is the first version of COM to support asynchronous method calls, which permit clients to make nonblocking calls to COM objects and objects to process incoming calls without blocking the calling threads. COM clients benefit from asynchronous method calls because they can continue working while waiting for outbound calls to return. Objects benefit because they can queue incoming calls and service them from a thread pool. Our SieveClient and SieveServer sample apps demonstrate how to create and use asynchronous clients and servers in COM-based distributed applications.

Jeff Prosise

MSDN Magazine April 2000

Array List with unique id while adding student info

Hello Frds,

I'm having arraylist to add student info but i have to create unique id per record below is my class.

Student objStudent=new Student(123,"Nj");

public class Student
  private string name;
private int RollId;
public string Name

    get { return name; }
set { name = value; }

public int Id
    get { return RollId; }
set { RollId = value; }
public Employee(string name, int id)


reusable components and unique ids


I'm trying to create reusable "zones" but am having trouble figuring out how to give them all unique ids.

What I'd like is to be able to create a component which can be put on an mvc page using the usercontrol syntax or using RenderAction or RenderPartial.  I want to be able to update these components' content using ajax, so I need someway to reference them by id.  However, there is no mechanism in MVC that wraps anything in a div or something like that.

I've learned that if I extend ViewUserControl and put the controls on the page like so:

<Zones:TestControl runat="server" ID="TestControl1" />

Then I can use the 'ClientID' property to get the unique ID generated.  However, if I use RenderAction or RenderPartial in another request, obviously the control hierarchy is missing, so the ID is just 1.  So to get around this I made a simple base class like so:

public class BaseZone<TModel> : System.Web.Mvc.ViewUserControl<TModel>
        protected string zoneId;

        public string ZoneId
                string zoneId = ViewData["ZoneId"] as string;
                if (String.IsNullOrEmpty(zoneId))
                    return this.C

Problems creating a BDC file that use a unique select statment


I'm trying to build an BDC file that will pull information back from two tables in an Oracle database, I can import it without any errors, but then it tells me I do not have a filter when I try and select an item.  When I add a filter I get an error when I import the file.  The error I get is the following.
"Application definition import failed. The following error occurred: The IdentifierName Attribute of the TypeDescriptor named 'TestDate' of the Parameter named ':TestDate' of the Method named 'Get_TestTwelve_List' of the Entity named 'TestTwelve' does not match any of the defined Identifiers for the Entity. Error was encountered at or just before Line: '133' and Position: '16'."

Here is the section of

      <Property Name="RdbCommandText" Type="System.String"><![CDATA[

how to automatically save new file into document library with a unique name or ID?

I've created a form using MS Word Document (2007) and lock it (protect it) so that users will be able to fill in the required fields.
then i've created a Content Type and uploaded the MS word form to be used as a template.

Then I've created a document library and enabled the content type and associate the above form for the library, so that when users click on New button the form will open.

everythings goes fine till here.

The problem is when users clicks on New and save the file back to the library, It doesn't save it with a unique name, instead it is over writting the existing one.
in other words, if employee 1 fill up the form and save it and later on employee 2 accessed the library and fill up a new form, he will overwrite what employee 1 has already saved!!

Is there a way to give every new created file a unique name? maybe (username+time)??

this my query works fine, i need to eliminate when resultset zero

hithis is the query working fineSELECT a.Selection,a.SizeRange,a.Thickness,       ISNULL(a.Assotment,0) - ISNULL(b.Issue,0)  AS difference1      FROM ( SELECT Selection,SizeRange,Thickness,                SUM(Pcs) AS Assotment            FROM  dbo.WBCAssortDescp where LotNo='LWC2'          group by Selection,SizeRange,Thickness) AS a LEFT OUTER   JOIN (SELECT Selections,SizeRange,Thickness,                SUM(Pieces) AS Issue            FROM dbo.WBIssue Where LotNo='LWC2'           group by Selections,SizeRange,Thickness) AS b on b.Selections=a.Selection and b.SizeRange=a.SizeRange and a.Thickness=b.ThicknessSELECT a.Se,a.Si.Th,      ISNULL(a.ent,0) - ISNULL(b.Ise,0)  AS difference1   FROM ( SELECT Se,Si,Th,               SUM(Pcs) AS ent           FROM  dbo.Table1where No='C2'         group by Se,Si,Th) AS aLEFT OUTER  JOIN (SELECT Ses,Si,Th,               SUM(Pieces) AS Ise         &nbs

CPU unique ID

Hi. I have written this simple maxscript to extract CPU ID. I want that to create a request code for evaluation process, so it must be a unique number in the world. -------- dotnet.loadAssembly @"System.Management.dll" mc = dotNetObject "System.Management.ManagementClass" "Win32_Processor" moc = dotNetClass "System.Management.ManagementObjectCollection" moc = mc.GetInstances() enumerator = moc.GetEnumerator() while enumerator.MoveNext() do ( mo = enumerator.current append CPUID ( mo.Properties.Item["ProcessorId"].value ) ) -------- Does system.management.managementClass involve a unique ID? Thanks for any help

Update with unique random generated values.

Hi there, I have an issue with an update of a column with unique random generated values, using SQL 2005. What I want to achieve is to create unique username for a list of let's say 1000 rows. My approach, which may be wrong, is as follows: to create a view to retrieve a random generated number of 7 digits; to use a function that retrieves the number from the view and checks if it is unique in the table or not (if it is, the number is returned, if it is not, a new one will be generated and so on); to update the table using that random generated number. The problem is that it does not work. It does not generate unique numbers, not all the times (you have to test by running the code few times). I suspect it is something with the update, but not sure how to solve it. Here are the steps to reproduce the problem. Create the table: CREATE TABLE [dbo].[TB_Temp]( [ID] [int] IDENTITY(1,1) NOT NULL, [ADM_USERNAME] [nvarchar](7) COLLATE Latin1_General_CI_AS NULL, ) ON [PRIMARY] Add some test rows: DECLARE @i INT SET @i = 0 WHILE @i <= 1000 BEGIN INSERT INTO TB_TEMP (ADM_USERNAME) VALUES ('') SET @i = @i +1 END Create the view to random generate 7 digits numbers: CREATE VIEW vw_RandNumberForAdminUserName AS SELECT ROUND((9999999 - 1000000 - 1) * RAND() + 1000000, 0) AS RandNumber Create the function to retrieve the unique 7 digits number: CREATE FUNCTION [dbo].[fn

How to eliminate html tags from text boxes

Hi all,   In my application I am using a login screen. While a new user registers he has to fill the First name and Last name. There is a user search option. The details of the users will be shown in the user details page. Some users try to add html tags like </td></tr> with first name and last name. So after rendering from DB the page alignment is breaking.   How to fix this problem??   How can I avoid html tags while entering the user details?   Please give me a solution:-   Thank You  

Unique filtered index

Hi Friends   Here is my scenario Employee ( EmployeeID int, EmployeeName varchar(50), EmployeeCode varchar(15), IsDeleted bit ) I created a non clustered unique filtered index as below, but it doesn't work for me. That is to say, I cant create two rows with same EmployeeCode and different IsDeleted values. I want to maintain the unique filtered index on Employee code having IsDeleted = 0 CREATE UNIQUE NONCLUSTERED INDEX [U_Nix_User_EmployeeCode] ON [dbo].[Employee] ( [EmployeeCode] ASC ) WHERE ([IsDeleted]=(0)) GO If that is the way it works, Do I create trigger to enforce such a constraint? Thanks in advance for any help Best Regards Asharaf MCTS, http://asharafaliptb.wordpress.com

how to have a unique hyperlink that will add the data to a database

I have a webform that writes respondent info to a sql data base. I want to send a email campaign and use a unique identifier so that if 1. joe clicks on his link http://www.test1.aspx?209and 2. tim clicks on his link http://www.test1.aspx?603that when they click the form submit the data gets written into the correct row where 209 and 603 are their respondent numbers already in the data base.This is my first attempt using c# and I couldn't find anything in my books about it.ThanksBob

Unique quotes site Sharepoint 2010

Hello. Sharepoint Server 2010 Standart. There are sites collection, with a quota template to 5Gb. Some sites require different quotes than the rest of the family. Question: how these sites change the quota template to a non-quota template the entire sites collection. Structure: sitecollection (quoteSC) | site1 (inherits quoteSC) | site 1.1 (inherits quoteSC) | site 1.1.1 I want custom quote for this site!

Where is the document library setting "Unique file names"?

Live can be so simple if only… ;-).   When using DMS functionality unique file names must be possible. The name is an unimportant attribute when using Meta data. So why can I not choose somewhere in the document library settings something like:   ·         Generate unique filenames Or ·         Do not allow overwrite existing filenames   Maybe in the first service pack?   MS? Please, please, please  

MySites vs. Sub-sites - Can security be unique for each subsite

Good Day; I have a sharepoint farm with several 100,000 mysites, each of these mysites consumes 2MB of space when being set up.  There is no need for this in the way we implement and use sharepoint.  As we are moving from Sharepoint 2007 to Sharepoint 2010 I am looking to change our format if possible.  What I am thinking is to change from individual MySites for each user and move to 1 MySite for each organization and then a sub-site for each user in that organization.  My question is, if I create an MySite named Company-A and then have 600 sub-sites below it, named User-1, User-2,...User600 for example, can I set up individual security on each sub-site or is their security profile inherited from their main MySite.  For further detail I need to offer individuals the ability to control their own security or have the company control the security for them but some users will have more permissions that others, some will be able to use difference services and service apps while others will have very limited access.  I can do this when I give each user their own MySite but that is a lot of overhead, so by switching to 1 MySite per Orgnaization and individual sub-sites, I save a lot of space, overhead, and increase my performance of crawls, etc... Can what I am thinking be done? How granular is security trimming for sub-sites? Thanks C
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend