Transact SQL :: INSERT Script To Allow Ampersands And Apostrophes

Jun 1, 2015

I work with both Oracle and SQL Server databases (most of the time Oracle) and I was wondering if there is a function that allows ampersands and apostrophes to be inserted into the database. Oracle has a function called SET DEFINE OFF and that allows for ampersands and apostrophes to be inserted without giving me an error. Is there something similar in SQL Server? I'm migrating some data and quite few rows have ampersands and apostrophes.

View 4 Replies


ADVERTISEMENT

Complex Use Of Apostrophes

Dec 1, 2006

Hello,
could someone help with this query in a stored proc.?
SET @SQL = 'SET ''' + @avgwgt + ''' = '
'(SELECT AVG(AverageWeight)
FROM CageFishHistory where CageID IN (' + @cagearray + ')
and ItemDate =''' + CONVERT(varchar(23),@startdate) + ''')'
EXEC @SQL
I'm trying to get an average value across  dynamically selected rows. (I'm using a list array to deliver the selection to the stored proc). I need to re-use the average value within the procedure,so it's not enough to output it as a column of the resultset - EG. 'Select AVG(AverageWeight) as AvgWgt' .  If I take out the @avgwgt line it works fine, but otherwise I'm getting this error:
"Incorrect syntax near '(SELECT AVG(AverageWeight)
FROM CageFishHistory where CageID IN ('."
It may be that I can access a column of the resultset in the rest of the procedure, and that would help avoid the use of pesky apostrophes, but I don't know how to do it.

View 3 Replies View Related

Apostrophes, Etc. In WHERE Statements?

Apr 11, 2007

How do I handle and apostrophes and other punctuation in stored procedure Sql statements:
SELECT        L_ID, L_NameFROM            tblHVACContractorsWHERE        (L_Name = 'Mare's Heating & Cooling Services')

View 5 Replies View Related

SQL Datasource And 'Apostrophes'

Jan 2, 2008

I am using a SQLDatasource to populate a dataview as illustrated below.  I run into a problem when I search for a "LastName" that includes an (') Apostrophe ( e.g. O'Reilly) . Searchin for the whole name there is no problem, but when I search for simply O, or O' I get errors.
 I am not sure ...when to address names with an apostrophe...
1) On insertion to the database (using a  "Replace(LastName, "'", "''") 2)  or after they have been entered and they are to be searched for.
If scenario 1, can anyone provide the best way to do this...If scenario 2, how would that be worked into the SQL Datasource code below....
I have tried several variations with the times SQL Datasource to no avail....
I would appreciate any help !
Thanks !
<asp:SqlDataSource ID="SqlDataSource1" runat="server"ConnectionString="<%$ ConnectionStrings:ClinicTest2ConnectionString1 %>"
SelectCommand="SELECT [PatientID], [Accession], [FirstName], [LastName], [Address1], [City], [strddlPatientState], [ZIP], [DOB] FROM [ClinicalPatient] WHERE [LastName] LIKE @LastName ORDER BY [LastName],[FirstName]ASC">
 
<SelectParameters>
<asp:QueryStringParameter Name="LastName" QueryStringField="NameSearch_Result" />
</SelectParameters>
</asp:SqlDataSource>

View 5 Replies View Related

NEED Query To Find Apostrophes In Table

Jan 18, 2006

I've tried everything I can think of to find all the records in a table column (lastname) that contain an apostrophe. I know they are there (O'Brian, D'Marcus, etc.) However, I keep getting syntax errors.

Could someone PLEASE help?!!

Thanks,
Karen

View 3 Replies View Related

SQL Server 2k Querying Varchar Without Apostrophes

Jul 20, 2005

I am currently migrating our Intranet from SQL Server 7 to SQL Server2000 and have hit a problem with one of the applications. Theapplication in question executes the folloiwing query against thedatabase:select * from employee where emp_id = 760In SQL Server 7 this works without a problem, however, in SQL server2k the following error is returned:[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error convertingthe varchar value 'Con25' to a column of data type int.This is clearly because the column emp_id is a varchar, I understandthat this code has not exactly followed best practices but do not wantto have to trawl through the application and surround all instanceswith apostrophes.Is it possible to make SQL 2k act in the same way as SQL 7 or will Ihave to trawl through the code and correct the SQL statements.Thanks for any help.John

View 2 Replies View Related

Help: MS-Word Apostrophes In Query Analyzer

Jul 20, 2005

After creating an IN clause from a bunch of character strings created by aWord macro, Query Analyzer complains about a syntax error. The macro takes acolumn full of character strings and wraps apostrophes (single-quotes)around each string and adds a comma to the end of each line, ready to pasteinto a Query Analyzer session. The problem is that Query Analyzer doesn'trecognize the MS-Word apostrophes. It has nothing to do with the standardapostrophe/quote problems that some people face when dealing with embeddedquotes.Can anyone suggest how to produce single-quote characters in MS-Word thatQuery Analyzer understands?Thank you.

View 2 Replies View Related

Apostrophes Replaced By Question Marks Problem... Somebody Must Have A Fix

Dec 7, 2007

Hi I have an asp.net 2.0, web app with a sql 2000 db.  I am having a problem when users cut and past content from Word and Excel and past it into a textbox apostrophes are replaced as question marks when saved to db.  I have set the following line in my web.config which did not resolve the problem<globalization requestEncoding="iso-8859-1" responseEncoding="iso-8859-1" fileEncoding="iso-8859-1" culture="en-GB" uiCulture="en-GB"/> I have also read many posts, but have not found a resolutionhttp://www.codingforums.com/showthread.php?t=124609I cant do a find and replace of the character  before insertion into DB, as this would involve visiting over 90 pages and changing every insert statement. Is there a way I a can force my sql server to only allow characters in a certain format, eg iso-8859-1 to resolve this problem Please help somebody must have a resolutionMany thanks in advance
 

View 2 Replies View Related

Inserting Text Into Table Replaces Apostrophes With ?

Jul 20, 2005

When we insert text into field in a table, SQL SERVER apparentlyreplaces apostrophes with question marks -- is there a way to not havethis occur? We don't have this happen with the mySQL databases thatwe also support.Much help appreciated.

View 1 Replies View Related

Apostrophes In Input String Terminating Update Statement

Sep 7, 2006

Hi.

I have an update statement that accepts
a user's text input. problem is that the string
terminates the sql update statement if there is
an apostrophe in it. so, headline='i like my brother's car"
willl terminate after "brother". "s car" is read as sql.

how is this resolved?



Code:


Dim MyCmd2 As New Data.SqlClient.SqlCommand("SET ANSI_WARNINGS OFF " & _
"UPDATE EditProfile " & _
"SET headline='"+ Me.tb_headline.Value+"', about_me='"+ Me.ta_aboutme.Value+"', edit_date='"+System.DateTime.Now.ToString+"' WHERE email_address='"+Context.User.Identity.Name.ToString+"' " & _
"SET ANSI_WARNINGS ON ", MyConn)

View 4 Replies View Related

SQL Server 2012 :: Encoding With Single Apostrophes In FOR XML PATH

Oct 16, 2014

Here is my problem:-

declare @test as varchar(32)
declare @test2 as varchar(32)

set @test='today''s problem'
set @test2='my <string> '

select @test as '@attribute' for xml path ('myrow')
select @test2 as '@attribute' for xml path ('myrow')

I want for xml path to correctly encode the single apostrophe as &apos but the single apostrophe doesn't get encoded. In the second example the greater and less than does get encoded.

View 4 Replies View Related

Transact SQL Insert Problem

Feb 14, 2006

I have a Stored Procedure that executes another Stored Procedure that returns rows containing two columns. I need to insert this data into a temporary table with two columns. I have tried the following statement and it errors out with
Insert Error: Column name or number of supplied values does not match table definition.

INSERT INTO #tblTemp([Customer ID], EmailAddress) exec frmCustomer

The insert statement is wrong. Can you help with a solution?

View 3 Replies View Related

Transact SQL :: How To INSERT Column Into MyTable

Jun 8, 2015

How to INSERT new column(Field) into MyTable

1. FirstName nvarchar(50)
2. LastName nvarchar(100)
3. Student bit Checked
4. CreateDate datetime
5. HwoOld float Checked

View 6 Replies View Related

Transact SQL :: How To Insert Values From One Table To Another

Sep 17, 2015

I am trying to insert values from a temp table #TableName to a db table.

CATEGORY table- CategoryId, CategoryName, CategoryDescription

Then I did this :
Select CategoryName 
into #TableName 
from CATEGORY

Now I'm doing this :
Insert into #TestTable values(1,'This is:'+CategoryName)
select CategoryName from #Test 
CategoryID right now is not PK.

So, the intention is to insert as many CategoryNames available into TestTable with id 1 and category name edited as shown in Inset statement.

What is wrong with this query. Its not working.

View 12 Replies View Related

Transact SQL :: Insert Into With Cast Datetime

Aug 10, 2015

I am trying to automate a load of insert cmd but some of them contain date times so i am trying to insert the following but keep getting

Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.

What is wrong with the cmd??

INSERT INTO client VALUES (100, NULL, NULL, NULL, NULL, 1, NULL, 0, 0, 0, 0, 0, NULL,Cast( '2013-03-11 10:54:46.529' as datetime))

View 11 Replies View Related

Transact SQL :: Insert Row If It Does Not Exist Already In Table

Sep 27, 2011

i need to write a query that insert in A table if and only if the row does not exist already in the table (the source is a select statement).
i tried the following:
 
insert into [A]
  select * from [B]
  where  Not EXISTS (select * from [A])
 
table [A] is still empty, but it does not insert any thing! .. what i know is that the EXIST checks if the selected row exists in the subquery, ain't ?

View 9 Replies View Related

Help Creating A Transact SQL Insert Statement

Jun 3, 2006

Hi there can anyone help me to create a SQL Insert Statement. I dont know SQL at all.

To explain, I have two web pages. search.asp and results.asp.

search.asp has the following.

Form Name: searchForm
Set to: Post
Action: results.asp
Text Field: Keyword
Drop Down: CategoryTable
Drop Down: Location
UserName Session Variable: MM_UserName

results.asp has the following SQL which pulls all the results.

SELECT SupplierName, Location, ShortDescription, TimberSpecies, CategoryTitle, Country, CustomerType
FROM Query1
WHERE TimberSpecies LIKE '%MMColParam%' AND CategoryTitle LIKE '%MMColParam2%' AND Location LIKE '%MMColParam3%' AND CustomerType = 'Trade/Retail'
ORDER BY CategoryTitle, TimberSpecies ASC

The database & form I want to insert into.

tblSearcheResults
idSearch (AutoNumber)
location (Text) "Want to insert the 'Location' result here"
category (Text) "Want to insert the 'CategoryTable' result here"
user (Text) "Want to insert the UserName Session Variable result here"
result (Text) "Want to insert the 'Keyword' result here"

Please ask if u need more info.

Mally

View 1 Replies View Related

Insert Records Using EXEC Syntax In Transact

Sep 14, 2004

Hi all,

I have to insert records using transact iin the stored procedure. I have some thing like:

DECLARE @Err varchar(100)
DECLARE insertQ varchar(1000)

SET @Err = 'Insertion data'

SET @insertQ =('INSERT INTO dbo.T_ERRORLOG (ERROR_DESCR) VALUES(' + @Err + ')')

EXEC insertQ

But it don't work. Can you help me to solve the problem plz?

Thanks a lot

TT

View 4 Replies View Related

Transact SQL :: Bulk Insert 0 Rows Affected

May 15, 2015

I have a file which has some wind data that i am trying to import into a sql data base through bulk insert. if the script works as it supposed i should see 144 rows impacted but i see 0 rows affected. 

BULK INSERT TOWER.RAWINTERFACE_1058 FROM 'C:Temp900020150427583.txt' 
WITH(CHECK_CONSTRAINTS,CODEPAGE='RAW',DATAFILETYPE='char',FIELDTERMINATOR=' ',ROWTERMINATOR='
',FIRSTROW=172)

The code works if the file is large but if its small 0 rows are affected. and also if i remove the header rows then the file works again. want to understand what is going on here. i am including the screen shot of the file in notepad++. I have tried changing the row terminator to ' ' , ' ' and also tried to change the codepage but nothing seems to work. No error file is being generated either, if i give a error file option. 

View 7 Replies View Related

Transact SQL :: Passing C++ / C# Array To INSERT Command

Aug 13, 2015

I have to send an array, which are generated in C++ (or C#) to an SQL-INSERT. Something like this:

INSERT INTO Table1
(Col1,Col2)
VALUES(:a,:b)
// a and b are my arrays//:a=A,B,C,D.....//:b=1,2,3,...

Is there any way to do something like my prototype in MS SQL Server? If yes how should be my INSERT? 

View 3 Replies View Related

Transact SQL :: INSERT Specific Data To Other Table

Aug 10, 2015

I am still learning T-SQL .Lets consider the table below, ID 1-3 shows our purchase transactions from various Vendors and ID 4-6 shows our payments to them

Table 1 - VendorTransactions

ID     PARTY    AMOUNT   VOUCHER
---------------------------------------
1       A               5000              Purchase
2       B               3000              Purchase
3       C               2000              Purchase

4       A               3000              Payment
5       B               1000              Payment
6       C               2000              Payment
7       A               1000              Payment


Now we have a blank table Table 2 - Liabilities

ID     PARTY    AMOUNT 

I want that SQL should look for each individual party from Table 1 and Calculate TOTAL PURCHASE and TOTAL PAYMENTS and then deduct TOTAL PAYMENTS from TOTAL PURCHASE so we get the remaining balance due for each party and then add the DIFFERENCE AMOUNT alongwith PARTY to the TABLE 2 so I can get the desired result like below

ID     PARTY    AMOUNT
-------------------------
1       A               1000              
2       B               2000              
3       C               0       

View 3 Replies View Related

Transact SQL :: Insert On Merge Statement Not Working

Oct 7, 2015

In a t-sql 2012 merge statement that is listed below, the insert statement on the merge statement listed below is not working. The update statement works though.

Merge test.dbo.LockCombination AS LKC1
USING
(select LKC.lockID,LKC.seq,A.lockCombo1,A.schoolnumber
from
[Inputtb] A
JOIN test.dbo.School SCH ON A.schoolnumber = SCH.type
JOIN test.dbo.Locker LKR ON SCH.schoolID = LKR.schoolID AND A.lockerNumber = LKR.number
 
[code]...

Thus would you tell me what I need to do to make the insert statement work on the merge statement listed above?

View 10 Replies View Related

Transact SQL :: Format File For Bulk Insert

May 16, 2012

I need fmt(format ) file for below values

“Stuid”,”Stuname”,”Class”,”DOJ”,”English”,”Math”,”Science”
"S1","Ram","10/31/2011,Monday",40,32,50
"S2","Bala","10/31/2011,Monday",50,45,69
"S3","Sam","10/31/2011,Monday",74,78,79
"S4","Jon","10/31/2011,Monday",65,58,89
"S5","Jos","10/31/2011,Monday",41,25,69
"S6","Jim","10/31/2011,Monday",74,41,41
"S7","Jack","10/31/2011,Monday",98,57,47
"S8","Sate","10/31/2011,Monday",87,73,45
"S9","Brb","10/31/2011,Monday",47,89,65
"S10","Jom","10/31/2011,Monday",14,100,47

View 15 Replies View Related

Transact SQL :: Generate Insert Order Script

Apr 22, 2015

I am using SQL 2012 SE. I have 2 databases say A and B with same structure and relationships. There are 65 tables in each database. A is already replicating data to database C for 35 tables. Now I need to move data from A to B which is greater than getdate()-1 everyday  for all the tables and once the move is done I need to delete this data from A. And samething the next day. Since this is for 65 tables its challenging to identify the insert order. Once the insert order is identified the delete order will be the reverse of it.

Is there a tool or any SP that could generate the insert order script? The generate scripts data only is generating the entire data and these databases are almost 400GB. So I thought of generating a schema only script and then create an empty database with it and then generate data only to identify the order of insert. But it wont generate anything since there is no data.

View 10 Replies View Related

Transact SQL :: Insert Records From Multiple Tables

Aug 30, 2015

This is a bit lengthy, but lets say we have three tables

a) tblSaleStatementCustomer
b) tblCreditors
c) tblReceiptDue

which shows records like below

Table 1 - tblSaleStatementCustomer

ID   CustomerName     VoucherType    Outbound     Inbound     CustomerType
----------------------------------------------------------------------------------------------
1     ABC                              Sales                10000              0                   Dealer
2     MNC                             Sales                  9000              0                   Dealer
3     MNC                             Sales                  4000              0                   Dealer

Table 2 -  tblCreditors

ID   Name     OpeningBalance
----------------------------------------------------------------------------------------------
1     ABC          20000  
2     MNC         15000 
3     XBM         18000
4     XYZ          12000

View 2 Replies View Related

Transact SQL :: Additional Column With Bulk Insert?

Aug 11, 2015

Need to know a mode whereby somehow I can every time insert an additional column in a table while bulk inserting data to an existing table from a new flat file thus identifying the file from which, or the time when, the data was inserted in an existing table.

View 2 Replies View Related

Transact SQL :: Complex Query And Insert Data

Sep 1, 2015

I have three tables and all three are linked. Looking for query so that I can get the desired result. Notes for Table_A and Table_B:

ROW Data are given in the variables to insert the Row data. If these Row data are already exist with the exactly same sequence in the row of table then don't need to INSERT data again.If these variable date doen't exist then need to add this row.

Notes for Table_C:

Seq_id_Table_A is a Seq_id of #table_A. Seq_id_Table_B is a Seq_id of #table_B.

--Table_A----------------------Variables for Table_A--------------------
Declare @table_A_Y char(4)='TRC'
Declare @table_A_Y1 char(2)='1'

[code]...

View 6 Replies View Related

Transact SQL :: Bulk Insert From Remote Server?

Nov 20, 2015

SQL Server 2012

I want to be able to run the following command from SSMS (as an ad-hoc query).

BULK INSERT Database_Name.dbo.Table_Name FROM 'serverfile.txt' WITH (FIELDTERMINATOR = '|', ROWTERMINATOR = '0x0a', MAXERRORS = 0);

When I do I get:

Msg 4861, Level 16, State 1, Line 1

Cannot bulk load because the file "serverfile.txt" could not be opened. Operating system error code 5(Access is denied.).

I have full access to the file.I can do the same command successfully if the file is stored on a local drive on the server.

According to my DBA I can not run it with a remote file location because I don't have the SA permission. His solution is for me to create a job that runs the command. I have done so and the job works correctly.

Is he correct that there is no way for me to be able to run it from SSMS without SA permissions?

View 5 Replies View Related

Transact SQL :: Insert Data Into Two Tables At A Time

Apr 20, 2015

i have these two tables

create table [dbo].[test1](
[test1_id] [int] identity(1,1) primary key,
[test2_id] [int] not null
)

[code]...

I want to insert the data into two tables in one insert statement. How can i do this using T-SQL ?

View 6 Replies View Related

Transact SQL :: CSV File - Bulk Insert Row Terminator

Nov 5, 2010

I have a CSV file that I am trying to bulk load into a temp table. The data in the file is all jumbled together, as in, there does not appear to be a row terminator. However, I do see a bunch of little rectangular boxes that I assume are the row terminators.

When I run the bulk insert, the data is treated as one string. For example... If I have 10 columns in the table, the 10 columns will be populated, but the remainder of the data is dumped into the last column.

Here are the row terminators I have used so far that haven't worked.

,
,
,
, CRLF,

View 31 Replies View Related

Transact SQL :: Key Increment Even On Failed Insert Into On One Column

May 28, 2015

The reason why cust_id started at #4 and not #1 is because I failed to insert property three times in a row for having "Tatoine" instead of "WI" or a state less than 5chars nchar(5) correct? Then when I did a valid statement, the row was created at the starting number of four. I imagine this prevents users from having duplicate cust_ids. This however is also where rollback and similar commands could be handy correct or is there something more obvious I'm missing on a failed "insert into" to not increment the cust_id. The three rows 1,2 and 3 do not exist I believe and are not null.  Having null values would of contradicted the table where two columns "not null" are a requirement.

CREATE TABLE customersnew
(
cust_idINTNOT NULL IDENTITY(1,1),
cust_nameNCHAR(50)NOT NULL,
cust_addressNCHAR(50)NULL ,
cust_cityNCHAR(50)NULL ,
cust_stateNCHAR(5)NULL ,

[code]...

View 2 Replies View Related

Transact SQL :: Insert Data Into Excel Using OPENDATASOURCE

May 14, 2015

While trying to insert data into existing XLS file, using below command, i am getting following error.

Insert into OPENDATASOURCE( 'Microsoft. ACE.OLEDB.12.0','Data Source=e:ediuploadhello1.xlsx;Extended Properties=Excel 12.0')...[Sheet1$]
Select top 50 product_no From product_mst
Msg 7343, Level 16, State 2, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" could not INSERT INTO table "[Microsoft.ACE.OLEDB.12.0]". Unknown provider error.

View 2 Replies View Related

Transact SQL :: XML Data Column - Insert Into Another Table

May 29, 2015

I have table with about 10000 rows,  there is a column named  Raw_XMLData is defined as varchar but data is xml format.  

I try to insert into another table, if Raw_XMLData column has is valid xml data?

Is it possible to do in T sql?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved