Solved

T-SQL to Update Table Dynamically

Posted on 2016-10-07
2
30 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 45

Accepted Solution

by:
Vitor Montalvão earned 500 total points
Comment Utility
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
Comment Utility
Thanks a lot Vitor.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now