Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6806911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:46:04+00:00 2026-05-26T19:46:04+00:00

declare @T table ( ID int identity primary key, FBK_ID BIGINT null, TWT_ID BIGINT

  • 0
declare @T table
(
  ID int identity primary key, 
  FBK_ID BIGINT null, 
  TWT_ID BIGINT null,
  LNK_ID NVARCHAR(50) null
);

Each record can ONLY have either a FBK_ID or a TWT_ID or a LNK_ID. No records have multiple values on those fields.

So mainly some records will have FacebookID values, some others have TwitterID, some others have LinkedInID.

QUESTIONS:
what is the fastest and cleanest way to do this?

Select ID, Type from @T

….where Type is a nvarchar(10) equal to either ‘Facebook’ or ‘Twitter’ or ‘LinkedIn’ depending on who has a value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:46:05+00:00Added an answer on May 26, 2026 at 7:46 pm

    You could do something like this:

    select 
    ID ,
    case when FBK_ID is not null then FBK_ID
         when TWT_ID is not null  then  TWT_ID 
    else LNK_ID end as LinkID
    from @t 
    where <rest of your conditions if any>
    

    You will get back the ID and one of the link IDS for the specific social network. If you want to know, additionally, to what kind of social network does the LinkID returned belongs to, you can add an extra column as so:

    select 
    ID ,
    case when FBK_ID is not null then FBK_ID,
         when TWT_ID is not null  then  TWT_ID 
    else LNK_ID end as LinkID,
    case when FBK_ID is not null then 'F'
         when TWT_ID is not null  then  'T'
    else 'L' end as LinkIDFrom
    from @t 
    where <rest of your conditions if any>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this: create table Location( LocationId int identity(1,1) not null primary key, Address nvarchar(max)
Consider the following design: Company TABLE ( CompanyId int NOT NULL IDENTITY PRIMARY KEY,
Let's say I have a table my_table(id int identity(1,1) not null primary key, data
I have this query DECLARE @Test TABLE ( RowID INT IDENTITY(1,1) PRIMARY KEY ,[Name]VARCHAR(10)
Sql: CREATE TABLE OldTable ( TaskId INT PRIMARY KEY IDENTITY, TaskName VARCHAR(32) ) CREATE
I have the below Declare @tbl Table(Id int identity, SomeCol varchar(10) not null) Begin
Table definition: CREATE TABLE [dbo].[AllErrors]( [ID] [int] IDENTITY(1,1) NOT NULL, [DomainLogin] [nvarchar](50) NULL, [ExceptionDate]
Here's what the table looks like: create table Shipping ( ShippingId int primary key
I have the following SQL script: DECLARE @temp table ( ID int IDENTITY(1, 1),
I have a table like this: CREATE TABLE [dbo].[Scores]( [Id] [int] IDENTITY(1,1) NOT NULL,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.