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 9011513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:45:17+00:00 2026-06-16T02:45:17+00:00

How can I Fill Declare in Case When for each row When I use

  • 0

How can I Fill Declare in Case When for each row
When I use code below Sql say incorrect syntax near ‘=’
ex:

Declare @Key1 nvarchar(100)
Declare @Key2 nvarchar(100)
Declare @Key3 nvarchar(100)
Declare @Key4 nvarchar(100)

Select 
    Case
        When A.K = 'Key1' Then @Key1 = A.V
        When A.K = 'Key2' Then @Key2 = A.v
        When A.K = 'Key3' Then @Key3 = A.v
        When A.K = 'Key4' Then @Key4 = A.v

    End
From
(
    Select Left(col, CHARINDEX(':',col) - 1) AS K, Right(col, Len(col) - CHARINDEX(':',col)) AS V
    From 
    ( VALUES 
    ( 'Key1:Test1' ),
    ( 'Key2:Test2' ),
    ( 'Key3:Test3' ),
    ( 'Key4:Test4' ) ) AS col ( col ) 
) As A
  • 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-06-16T02:45:18+00:00Added an answer on June 16, 2026 at 2:45 am

    You can not assign a value in the case. Case can only return a value.

    You could use something like this instead.

    declare @Key1 nvarchar(100)
    declare @Key2 nvarchar(100)
    declare @Key3 nvarchar(100)
    declare @Key4 nvarchar(100)
    
    select 
      @Key1 = P.Key1,
      @Key2 = P.Key2,
      @Key3 = P.Key3,
      @Key4 = P.Key4
    from
    (
        select left(col, CHARINDEX(':',col) - 1) as K, 
               right(col, Len(col) - CHARINDEX(':',col)) as V
        from 
        ( values 
        ( 'Key1:Test1' ),
        ( 'Key2:Test2' ),
        ( 'Key3:Test3' ),
        ( 'Key4:Test4' ) ) as col ( col ) 
    ) as A
    pivot (min(A.V) for A.K in (Key1, Key2, Key3, Key4)) as P
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I declare int array in SQL Server? After fill it, I would
I have a table with a form below it. You can fill out the
Is there an image processing algorithm that can fill these gaps within an image?
I have a from where you can fill in any combination of your home,
I am creating a HTML layout where user can fill the data and save
In Short: I have a PDF that customers can fill out. When they press
I know in C++ and in PHP you can fill a string or a
I have an ecommerce gift store where users can fill out a gift-card for
I'm a pretty new C# programmer. I was wondering if someone can fill me
On a CAShapeLayer , I've drawn a closed UIBezierPath . I can fill this

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.