SQL Server :: How To Use Distinct On A Single Column From A List Of Columns

Jan 21, 2011

I would like to know if there is a way that I can use DISTINCT on one column's values but need to show other columns where the value of the DISTINCT column is equal to another table's column

View 7 Replies


Similar Messages:

SQL Server :: How To Select All Columns Of Table But To Distinct By One Column

Dec 29, 2010

How can i select all columns of table but to distinct by one column? i am tryin to figure it out without success, i know how to make distinct (select distinct column from table, but i need all the values from the table and to distinct by Delcompany.

my line is:

[Code]....

View 13 Replies

SQL Server :: How To Get Distinct Column Name Which Are Having Distinct Values In The Column

Feb 4, 2011

I have one table(tableName is getDetails and having three column ID, Name, City)

View 6 Replies

ADO.NET :: Fetching Only Distinct Values Of Particular Column To Assign To Dropdown List?

Nov 19, 2010

As I kept my fetched datatables into session and accessing it on another page there I am

wroking on datatable to fetch only distinct values of particular column to assign to dropdown list.

View 1 Replies

Select Distinct And Include Non-distinct Columns?

Apr 20, 2010

I would like to select a distinct query based on three fields and display the rest of the fields. For example,

I have firstname, lastname, address, city, state and zip, but I only want to use the distinct on these fields first and last name. However when i use the distinct function I get a distinct on all the selected rows. I just want to distinct firstname and lastname and display the other fields. for example,

Mary Smith New York
Mary Smithy New York
Mary Smith Maine

I would like the result to be:

Mary Smith New York
Mary Smithy New York

I don't care about Mary Smith Maine, because i am only using the distinct for "Mary Smith" firstname and last name and showing the city.

View 15 Replies

SQL Server :: How To Show Two Columns One Is The One Will Contain The Distinct Values From 'col'

Mar 30, 2011

I have a table 'tbl' and a column 'col'. The elements are like 1,1,2,2,2,3,4,4. Now I want to show two columns one is the one will contain the distinct values from 'col' like 1,2,3,4.... and second will contain the count for each of them like for above case it will be 2,3,1,2.

View 1 Replies

SQL Server :: Selecting Distinct Keys With Highest Value In Another Column?

Sep 25, 2010

I have a table with 2 columns that lookes something like this:

ChapterID | VersionNumber | VersionID |
1001 | 1 | 1004 |
1001 | 2 | 1005 |
1002 | 1 | 1006 |
1002 | 2 | 1007 |
1002 | 3 | 1008 |
1003 | 1 | 1009 |
1004 | 1 | 1010 |

what I wanna achieve is to have a statement that selects distinct uniqueid's from the chapterID field and with every duplicate I would like to have the record with the highest version number

Below is the result I would like to achieve:

ChapterID | VersionNumber | VersionID |
1001 | 2 | 1005 |
1002 | 3 | 1008 |
1003 | 1 | 1009 |
1004 | 1 | 1010 |

I have tried this statement:

Select Distinct ChapterID, max(VersionNumber) from Versions groupby ChapterID

and it works fine, but when I add the VersionID column like so:

Select Distinct ChapterID, VersionID, max(VersionNumber) from Versions group by ChapterID

it returns an error.

View 9 Replies

Data Controls :: Bind Multiple Columns From Database To Single Column Of GridView

May 7, 2015

Select tbl_name.name,tbl_midname.midname,tbl_last.lastname As name
From tbl_name
inner join tbl_midname on tbl_midname.id=tbl_name.id
inner join tbl_last on tbl_last.id=tbl_name.id
where tbl_name.id='1'

name mid name last name
Pavan Kumar Roy

How to bind all 3 column data in on column.

I need this result

Pavan Kumar Roy

View 1 Replies

SQL Server :: Query To Return Conditional Counts Both Distinct And Non Distinct?

Sep 30, 2010

I have the following table structure:

[code]....

The following query returns the default recordset:

[code]....

View 4 Replies

Insert Multiple Checkbox List Values Into Database In Single Column Using C#?

Aug 4, 2010

i use this to select one checkbox to isselected column how i convert this to multi checkboxlist to single column i use many ways more than 3 days without success

private void BindCheckBoxList()
{
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection(GetConnectionString());
try
{
connection.Open();
string sqlStatement = "SELECT * FROM boby";
SqlCommand sqlCmd = new SqlCommand(sqlStatement, connection);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
CheckBoxList1.RepeatColumns = 4; // set the number of columns in the CheckBoxList
CheckBoxList1.DataSource = dt;
CheckBoxList1.DataTextField = "Name"; // the items to be displayed in the list items
CheckBoxList1.DataValueField = "Name"; // the id of the items displayed
CheckBoxList1.DataBind();
//Setting the Selected Items in the ChecBoxList based from the value in the database
//to do this, lets iterate to each items in the list
for (int i = 0; i < dt.Rows.Count; i++)
{
if (!string.IsNullOrEmpty(dt.Rows[i]["IsSelected"].ToString()))
{
CheckBoxList1.Items[i].Selected = Convert.ToBoolean(dt.Rows[i]["IsSelected"]);
}
}
}
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Fetch Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
connection.Close();
}
}
private void Update(string name, bool isSelected)
{
SqlConnection connection = new SqlConnection(GetConnectionString());
SqlCommand cmd;
string sqlStatement = string.Empty;
try
{
connection.Open();
sqlStatement = "UPDATE handymen SET IsSelected = @IsSelected WHERE Name = @BizName";
cmd = new SqlCommand(sqlStatement, connection);
cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@IsSelected", isSelected);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert/Update error";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
connection.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindCheckBoxList();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = string.Empty;
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
str = CheckBoxList1.Items[i].Text;
Update(str, CheckBoxList1.Items[i].Selected);
}
}
//ReBind the List to retain the selected items on postbacks
BindCheckBoxList();
}

View 3 Replies

Data Controls :: Display Multiple Columns In Multiple Lines In Single Column In GridView

Aug 18, 2015

I have a question in gridview, I want to combine my two or more records into a single cell with two rowsfor Example i have a ID, Name, Year Start, and Year End for Column name in database and i want call it into my gridview that the Year Start and Year End will combine to Year like:

In Database

ID Name Year Start Year End

1 Yourname 2010 2015

In Gridview:

ID Name Year

1 Yourname 2010 2015

in a year column i want it to two row..

View 1 Replies

Data Controls :: Display Multiple Columns In Multiple Lines In Single TemplateField Column In GridView?

Aug 18, 2015

I want to bind three column with one row in gridview in asp.net with c#,

i want like this, 

Name | Info
----------------------
name | lastname

        | phone number

        | address

I get this by default

name | last name | phone number | address 

View 1 Replies

SQL Server :: Search A Word In All The Columns Of A Single Table?

Sep 17, 2010

How can I search a word in all the columns of a table?

View 4 Replies

DataSource Controls :: How To Select Multiple Columns With Distinct Key Word

Jan 2, 2010

there are multiple rows with same SubContact_No and with same value of some columns. for a single column I am firing query like

Select distinct (Financial_Status) from mtblSub_Contract where SubContract_No=@SubContract_No";

it's working fine.... (it's ok with a Single column)

But Now I need multiple columns value so how to query for this.

Select distinct (Financial_Status, colums2, column3) from mtblSub_Contract where SubContract_No=@SubContract_No"; is not working

So how to do that.

View 5 Replies

SQL Server :: How To Calculate A Column Data For Different Conditions Using Single Query

Jan 12, 2011

I am using below query to count a particular column data based on single condition.

[code].....

But I have to calculate for 3 more conditions. Is it possible to count based on 3 conditions(i.e. 2001 - 3000,3001 - 4000, 4001 - 5000,>5000) and I want result set for all the conditions?

View 8 Replies

ADO.NET :: Distinct Values From A Column In Datatable?

Sep 21, 2010

I have a datatable dt with 4 columns. I want to retrieve only distinct values from column1 of datatable.

How can I achieve this using c# code?

View 3 Replies

SQL Server :: Dynamic Nullable Columns Depending On The Value Of A Column?

Feb 11, 2011

I have a master document which is composed of other document types (some are required and some are not). While the master document's status is "Draft" I need to ignore all not nullable constraints (because the writer may decide to work on one of the children
documents that is not required and save as draft).

The closest solution I found for this problem is check constraints but I have not yet to see an example of this in check contraint and I'm not even sure if this is possible. Has anyone implemented a similar solution with check constraints (or any other methods)?

View 2 Replies

SQL Server :: Copy Data From Multiple Columns Into One Column?

Aug 26, 2010

My View has four columns with years, none of the rows have complete yearly data.

Current View

Columns 1-10, FY, Expr1, Expr2, Expr3
Some data, 2010 NULL,NULL, NULL
Some data, NULL, 2010, NULL, NULL
Some data, NULL, NULL, 2010, NULL
Some data, NULL, 2010, 2010, 2010
Some data, 2010, NULL, 2010, 2010,
Some data, NULL, NULL, 2010, NULL
Some data, 2010, 2010, NULL, 2010
Some data, NULL, NULL, NULL, 2010

A new column needs to relfect 2010 for each row in the View.

Goal New View
Columns 1-10, FY_NEW
Some data, 2010
Some data, 2010
Some data, 2010, etc. for each row in the view

I can not hard code the data as time moves forward next year rows will have 2012, etc.

How can I get lthe year, in this case 2010, into a new column regardless of the year?

View 10 Replies

SQL Server :: How To Combine The Data From The Two Text Boxes And Store It In Single Column

Jul 30, 2010

I have two textboxes

1.To get the Hour

2.To get the Minutes

From user.

And in the back end... i would to Combine the data from these text boxes and store it in single column..
For eg.

If textboxHours.Text="11";
textboxMinuetes.Text="56";
In the backend it should store like..
MeetingTime (column name)
11.56

View 2 Replies

SQL Server :: Combine Strings Separated By Single White Space In Column

Mar 10, 2011

i have a column in table and need to combine words seperated by single space, i am using sql server 2005.

DECLARE @text varchar(256)
SELECT @text = 'Micro Tech'

--required output MicroTech

View 3 Replies

SQL Server :: How To Get Month And Year In Single Column And Grouping The Data For All The Years And Months

Jan 10, 2011

For the below query (sdate is column name and table name is storedata)

View 2 Replies

C# - Get A List Of Distinct Items And Their Count?

Jan 6, 2010

I have an object, that has many properties but the only two to worry about are:

myobject.ID which is an int
myobject.Names which is a HashSet

Then I have a List of those objects that looks something similar to this:

List<myobject>

I use Linq to get a some of the data into a repeater, but I'm not sure how to get the list of Names and how often they show up.

Want to use Linq to avoid having to loop through the data.

As my tags should show, this is an ASP.NET solution using C#.

Some clarification:
Lets say I have just three items in my list:
Item 1 has John, Fred, Jack in its names.
Item 2 has John, Fred, Joe in its names.
Item 3 has John in its names.

I am trying to return the following:
John - 3
Fred - 2
Jack - 1
Joe - 1

Also, as a note I am familiar with having to write my own comparer for my object, I'm just missing the 'how to' for the overall solution in my thoughts.

View 2 Replies

DataSource Controls :: Returning All Rows Based On One Distinct Column?

May 18, 2010

Here is the query I have now which returns over 2 million records:

[Code]....

This works, but the result is littered with many rows that contain the same SSN. So how do I return only one row for each ssn? I cant use distinct because all of the other columns are already always different, this would return the same as above.

View 11 Replies

Three Columns Layout, Want Middle Column To Stretch Wider When Column 1 And 3 Are Empty?

Apr 11, 2010

I have a 3 column layout using table-less design.

[code]....

The CSS:

#left {width: 200px;float:left;display:inline;}
#content {width: 600px;float:left;display:inline;padding: 0 10px;}
#right {width: 160px;float:left;display:inline;}

I am using a web application, and I can't change the layout. By can't change, I mean the div's with left/content/right cannot be removed.

On some pages, both the left and right columns are completely empty. And I want the #content div to expand more than the 600px.

is this possible, without altering the HTML?

View 1 Replies

ADO.NET :: Is It Possible To Save "Collections" To A Single Varbinary(MAX) Field/column In A SQL Server 2008

Oct 9, 2010

I was thinking about the fastest way to retrieve a "set" of objects related to a specific user. For instance, if I was to create a website similar to Flickr where people upload lots and lots of photos(jpegs) what would be the fastest way to be able to retrieve those photos from the SQL Server database. Scenario 1: You store metadata about each file they upload to the website as a single row in a database table. Then when you want to retrieve a specific users uploaded files you simply scan the database file for every row matching the UserID and store them in memory.

SELECT PictureId, UserId, PathToFile, Caption, (etc.)

FROM Photos

WHERE UserId=@UserId

This, of course, gets all the information about all the photos a single user has uploaded. My concern with this approach is when the user activity goes from a few thousand to being in excess of a million.

This approach seems fine for a small website but does this method work for a million plus user website like Flicker or MySpace? When you have a million users and millions more photos does this approach still perform at acceptable speeds?

create a collection in memory of "ALL" the PictureIds' for a single user and store them in-memory, in a collection and then save this collection as a single VARBINARY(MAX) field in the SQL Server Database. So instead of having to find multiple records in the Photos database you would simply need to find one, which would include all the PhotoIds' that belong to the user. In essence, translating into the phrase, "If you find one, you have found them all". And improving server performance by leaps and bounds. I only have about a year experience in working with SQL Server and ASP.NET so Im not sure if this solution is practical, if its already been tried, if it can be done.

View 1 Replies







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