Solved

T-SQL to Update Table Dynamically

Posted on 2016-10-07
2
49 Views
Last Modified: 2016-10-07
I had this question after viewing T-SQL to Update Table Dynamically.

How to fix single qutation in this query:

DECLARE @ChangingAsIsColumnsToTheEquivelantValuesSQL varchar (255);
SET @ChangingAsIsColumnsToTheEquivelantValuesSQL = 'SELECT
  ID 
, ServiceFees
,(Case Financed 
   WHEN N'False' THEN N'F' WHEN N'True' THEN N'T' END) As Financed
,(Case OutsideBranches 
  WHEN N'False' THEN N'F' WHEN N'True' THEN N'F' END) As OutsideBranches
FROM MyTable

EXECUTE(@ChangingAsIsColumnsToTheEquivelantValuesSQL)

Open in new window



Thanks a lot in advance.
Harreni
0
Comment
Question by:Harreni
2 Comments
 
LVL 47

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 41833697
Just add another the single quote for each one:
DECLARE @ChangingAsIsColumnsToTheEquivelantValuesSQL varchar (255);
SET @ChangingAsIsColumnsToTheEquivelantValuesSQL = 'SELECT
  ID 
, ServiceFees
,(Case Financed 
   WHEN N''False'' THEN N''F'' WHEN N''True'' THEN N''T'' END) As Financed
,(Case OutsideBranches 
  WHEN N''False'' THEN N''F'' WHEN N''True'' THEN N''F'' END) As OutsideBranches
FROM MyTable'

EXECUTE(@ChangingAsIsColumnsToTheEquivelantValuesSQL)

Open in new window

0
 

Author Closing Comment

by:Harreni
ID: 41833717
Thanks a lot Vitor.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql server insert 12 30
Query Syntax 17 36
convert null in sql server 12 34
optimize stored procedure 6 29
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question