Choosing between two column values to return as single column value

I'm working on a social network where I store my friend GUIDs in a table with the following structure:

user1_guid       user2_guid

I am trying to write a query to return a single list of all a users' friends in a single column.  Depending on who initiates the friendship, a users' guid value can be in either of the two columns.  Here is the crazy sql I have come up with to give what I want, but I'm sure there's a better way...  Any ideas?

SELECT DISTINCT UserId
FROM espace_ProfileProperty
WHERE (UserId IN (SELECT CAST(REPLACE(CAST(user1_guid AS VarChar(36)) + CAST(user2_guid AS VarChar(36)), @userGuid, '') AS uniqueidentifier) AS UserId
FROM espace_UserConnection
WHERE (user1_guid = @userGuid) OR (user2_guid = @userGuid))) AND (UserId IN (SELECT UserId
FROM espace_ProfileProperty))
  
0
headchem
9/14/2007 8:12:53 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

1 Replies
995 Views

Similar Articles

[PageSpeed] 3

So... as usual, as soon as I post a question, the answer presents itself to me.  Here's my new sql:

 

SELECT     CASE WHEN user1_guid <> @userGuid THEN user1_guid ELSE user2_guid END AS user_guid
FROM (SELECT user1_guid, user2_guid
FROM espace.espace_UserConnection
WHERE (user1_guid = @userGuid) OR (user2_guid = @userGuid))
  
0
headchem
9/14/2007 9:04:09 PM
Reply:

Similar Artilces:

Matching each value out of multiple values to single column value
 Hi,  @whoposted in stored procedure holds value "agent  builder owner"  ( please note the space in between) My column  POSTED_BY  always holds one and only one value out of above 3.Example:       POSTED_BY  owneragent          etc... If  All / any of the value hold by  @whoposted matches with value of POSTED_BY column, i want to show that row in gridview.( Also, please note, str may hold different values depending on user selection. For example, it may ...

SQL Table Valued Function: Problem returning concatenated fields in single column
I have a SQL table valued function, which I would like to return a table with single column of type text that has various column values concatenated. All works fine when the column values being concatenated are NOT of type text. However, when one of the columns being concatenated has a value of type text, I have to split the text value down into sub-strings and cast each substring as varchar(8000). My problem is when I run the function, the result data gets cutt-off where the text column value reaches 8000. I thiught about using UPDATESTRING function, but was not sure how I would be ...

how to bind the value in dropdownlist wtih two database column values
 hai to alli am using dropdownlist i want to bind the two value to dropdownlisti have two column value, that two column value must bind in one dropdownlist using ,what i have to do Ramesh.Dhttp://rameshduraikannu.blogspot.com you dont... you need to combine them to on and bind. "Select (Field1 + ' ' + Field2) as Field3...."Then bind to Field3 i con,t understand siri am having the database like this one value is mangerand another value is rameshboth are seperate tablei want to bind like ramesh][mangerin a single dropdownlistso i identify that ramesh is ma...

dw is column value read.... column value sort ....make ranking nomber init!
dw is column value read. column value sort ....make ranking nomber init! dw�� ���� column�� ���� ������ ũ������� number�� �ޱ���� �մϴ�! �����ּ���! Could you explain this a little futher? I don't understand your question. On Fri, 11 Jun 1999 11:18:01 +0900, in powersoft.public.powerbuilder.datawindow ����ģ�� <hifrand@shinbiro.com> wrote: >dw is column value read. >column value sort ....make ranking nomber init! > >dw�� ���� column�� ���� ������ ũ������� number�� >�ޱ���� �մϴ�! > >�����ּ���! > > > --- Bruce Armstrong [Te...

How to place in DataGrids’s first column table’s column name, in second Datagrid’s column table’s column value?
Hello I use C#. I’m interesting are there samples solved my problem. Andrew. You will need to loop through the datasource of the datagrid or through the datagrid items and fetch the values for the second datagrid.Sonu Kapoor [MVP] Feel free to ask me any .NET question | Ajax Data Controls Forum Thank you! I solved my problem at the server cite. Andrew. ...

two field values in a single column of datagrid
In a datagrid is it possible to display two values that are fetched from the database in a single column of datagrid. for example if i am fetching Name, Age, Salary from database, is it possible to display Name and age in first column and salary in second column. if it is possible pls give me the code. sure, the easiest way is to convert this column to a template, ull have  a label wirh EVAL("Name") And another label beside it with EVAL("age")  RegardsRamzi--------------------------------------------Dont Forget to mark the post as answered once replied. You can retrieve the...

How do I check to see if a value returned from a sql datasource equals a listitem value
I'm trying to see if this listitem equals a value returned in my sql data source, but I get keep getting a error saying  'Item' is not a member of 'System.Web.UI.WebControls.SqlDataSource'.    How do I check if the employeeID returned is equal to the li.value? For Each li As ListItem In BillingEmployeeID.Items If li.Value = getEmployeewithMostOpenClient.Item("employeeID") ThenxxxxxxxEnd If NextNever make important decisions on a Monday! Try Items.FindByValue() or Items.FindByText() method. Something like this... string szValueFromDataso...

want to choose between URLs for a hyperlink column based on another columns value
I'd like to know if this is possible! I want to be able to select the URL I am  going to load when I click on a hyperlink column field. The value in another column will determine what URL is selected.    EXAMPLE Completion Date" DataField="Scheduled Completion Date">Completion Date" DataField="Scheduled Completion Date">Completion Date" DataField="Scheduled Completion Date">   Col1   Col2   1         T   2         S  ...

How do I extract a single value from a single column in a single row in a dataset?
First of all, thank you to everyone who takes time to answer basic questions in this forum. Your patience is deeply appreciated. For the past day, I've been trying to figure out how to access a single value in a row of a data set. The data layer tutorials by Scott Mitchell are helpful, but I still can't figure out how to extract a single value without looping through the data set. By passing a Client_ID to an instance of my data adapter, I am able to return a unique row that contains a column labeled Family_ID. However, I can't figure out how to access the value of that column on...

add two values from two columns...
hi, i need to add num of munths to a date in the same table. the code i have now present only the date whithout the add of the munths... ...... <td align="center"> <%# Container.DataItem("EquipmentLastChecked") %> </td> ...... thanks :) Could u post what you want to see in your server control?? I mean to ask what would be displayed by adding months to your date here.Shravan Addaypally MCP hi- fro example if i have 1/1/00 and i want to add 13 months i want to show the 1/2/01... i dont know how to add to the date i ...

SQL,Make Multiple values for multiple columns into one column separated by comma
Hi, I'm getting the result as this Name       Class       Subject------------------------------------------Anju         10             MathsAnju         10             Physics How to write the query to get the result like this Name       Class       Subjects------------...

Rotate single row into two (key, value) columns
  Hi, How can I convert this results : col 1 col 2 col 3 col 4 col 5 col 6 col 7 val 1 val 2 val 3 val 4 val 5 val 6 val 7 into this Col 1 val 1 Col 2 val 2 Col 3 val 3 Col 4 val 4 Col 5 val 5 Col 6 val 6 Col 7 val 7 This is a perfect task for PIVOT and UNPIVOT in SQL 2005 see http://msdn2.microsoft.com/en-us/librar...

INSERT INTO command (two columns) with one fixed value, one string with several values
I have a string with values value1,value2, value3, value(n) which I would like to append to my table. In the second column of my table I have a parameter which stays the same, so I end up with (if the parameter value is "123456") Column 1   |         Column 2 123456      |         Value1 123456      |         Value2 123456      |      &...

Mysql: insertrow with identity column doesn't return the identity column value
Mysql: insertrow with identity column doesn't return the identity column value Mysql:5.0.22 (connection using jdbc) pb10.2.0.8100. However it works with other databases. Also, the same works in other IDE's. I have a workaround for now to call last_insert_id() in the updateend event. however, this limits me to update one record at a time. any other solution like connection paramaters or something that i might be missing thanks vsv You have to edit the PBODBXXX.INI file to tell it how it's supposed to get the value. On 4 Aug 2006 16:22:22 -0700, "vsv...

Web resources about - Choosing between two column values to return as single column value - asp.net.sql-datasource

A Time for Choosing - Wikipedia, the free encyclopedia
In support of Goldwater, Reagan delivers the address, A Time for Choosing. The speech launches Reagan to national prominence. A Time for Choosing ...

Teens Choosing Tumblr, Foursquare Over Facebook
In terms of social media preferences, teenagers have been hard to quantify. A study released recently by youth market research firm Ypulse shows ...

Choosing a Path to Grad School - YouTube
How do I prepare myself for graduate school? How do I choose schools and programs to apply to and how do I know which school is the right one ...

NBA choosing to dig head in the sand over tanking stench
The NBA draft system is a mess. Whether Adam Silver likes it or not, perceptions of tanking will dog the league until the process for selecting ...

Unnecessary tests: Choosing Wisely campaign targets brain scans, food allergy tests
Common medical procedures including brain scans, food allergy tests and long-term reflux medication are unnecessary and possibly harmful for ...

Choosing an open-source CMS, part 3: Why we use WordPress
In the third part of a three-part series, we look at two organizations that have chosen WordPress as their content management system.

The concise guide to choosing a data centre partner
Part one: price, availability and power. Choosing a data centre partner is a long-term decision, and the initial stages of mapping requirements, ...

Sandy Hook survivor Kaitlin Roig-Debellis reveals hiding place in Choosing Hope book
HERS was the very first classroom when entering Sandy Hook Elementery School.

Pakistani Taliban choosing new leader
Sky News is Australia's leader in 24-hour news.

NBA: Kobe Bryant snubs Michael Jordan in choosing his dream pick-up team
Kobe Bryant passed over Michael Jordan for his ideal group to join in a pick-up basketball game, saying he'd take Magic Johnson as his backcourt ...

Resources last updated: 12/7/2015 12:41:28 PM