2

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?

TobyLL
  • 2,098
  • 2
  • 17
  • 23
Lalu
  • 168
  • 1
  • 2
  • 12

2 Answers2

6

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')
TobyLL
  • 2,098
  • 2
  • 17
  • 23
3

Option 1 : Use '' for ' (preferred)

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

Option 2 : Set quoted identifier off

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

MSDN Link for Quoted_Identifier

Deep
  • 3,162
  • 1
  • 12
  • 21