Monday 9 September 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...