Monday, September 9, 2019

sql - How to add a row in table with varchar type column, a word with inverted comma?




I have a table dbo.AccountTypes with following two columns



AccountTypeId    int         not null
AccountTypeName varchar(50) not null


I want to add a row with values 1 and Partner's Capital A/c for the respective columns. I tried following insert command but it does not work.




insert into dbo.AccountTypes (AccountTypeId, AccountTypeName)
values (1, "Partner's Capital A/c")


Please note inverted comma in the word Partner's Capital A/c



But it fails. Any suggestions?


Answer



Replace the single quote inside the string with two single quotes, and surround the string with single quotes:




insert into dbo.AccountTypes (AccountTypeId, AccountTypeName)
values (1, 'Partner''s Capital A/c')

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...