I had a procdure in SQL 7.0 in which I am using both single quote and double quotes for string values. This proceudreused to work fine in SQL 7.0 but when I upgraded SQL 7.0 to SQL 2000, this proceudre stopped working. When I changed the double quotes to single quotes, it worked fine.
below is the code of my sp it's giving my wrong result: 1 instead 0 and vice versa could you please check what's wrong with it: i think there is something related to @var2 in the code colored in orange.
Thanks!
Code:
ALTER PROCEDURE sp_name ( @param1 int = NULL, @param2 int = NULL, @Result int OUTPUT )
AS
DECLARE @var1 AS varchar(255) DECLARE @var2 AS varchar(255) DECLARE @x AS varchar(1000)
IF @param1 IS NOT NULL BEGIN SET @var1 = ( SELECT t1col1 FROM tabl1 WHERE t1col2 = @param1)
SET @var2 = ''
DECLARE crsr CURSOR FOR
SELECT t2col1 FROM tabl2 WHERE t2col2 = @var1
OPEN crsr FETCH NEXT FROM crsr INTO @x
WHILE @@FETCH_STATUS = 0 BEGIN SET @var2 = @var2 + '''' + @x + '''' + ', '
FETCH NEXT FROM crsr INTO @x END
CLOSE crsr DEALLOCATE crsr
SET @var2 = SUBSTRING(@var2, 1, LEN(@var2) - 1)
END ELSE BEGIN SET @var2 = (SELECT t2col1 FROM t2 WHERE tb2col3 = @param2) SET @var2 = '''' + @var2 + '''' END
PRINT @var2
IF EXISTS (SELECT * FROM tabl3 WHERE t3col1 IN (@var2)) OR EXISTS (SELECT * FROM tabl4 WHERE t4col1 IN (@var2)) BEGIN SET @Result = 1 END ELSE BEGIN SET @Result = 0 END
Your help would be appreciated if you could give me some idea about why SQL 2000 takes single quote(') as a default for string searching instead of double quotes("). I have couple of stored procedures which were developed with string comparison with double quotes in SQL 6.5. If any one knows how I can change default as a double quotes(") instead of single quote(') in SQL 2000, would be great. Thanks
select * from tblCalls where TNum = [NUMBER] and Street like '[TEXT]'
The problem is that the Street field contains street names with quotes (ex. DE L'ACADIE). When I run this query using this street name, it doesn't work because of the ' between the L and the A. How can I tell SQL to "ignore" the ' in the text?
Hi, I am creating a flat file connection to a .csv file In the columns section of the flatt file connection manager editor, I am not sure why the texts in the .csv file are shown with double quotes arouond them. They do not have "" in the .csv file. Thanks
Has previous work been done on this? Is their a library one can download? Here's the problem. In an aricle a person or author may make a statement about a subject or a person. I am making a database on this.
For example, here in Israel, PM Olmert may make a statement on the teacher's strike or on Abu Mazen. The article may say, speaking of Mazen, Olmert said such and such. PM Olmert said, "xxxxxxx......." with the previous material making it clear whathe was speaking of.
Right now I have ugly code. Is there a neat way of doing this?
If this is the wrong forum, can somebody direct me to the right forum?
I'm going crazy trying to figure out how to form this SQL query. I am querying an Informix linked server and I need to pass a variable date. I am using an expression to create the query like so
"Select count(*) from " + @[User::varDBName] + ":informix.doc_tl WHERE " + @[User::varDBName] +":informix.doc_tl.d_received = {D " + @[User::varDate] +"} "
The informix query needs the date to be {D "2007-01-15"} but for the life of me, I can't get the date enclosed in quotes.
The error I get is
An OLE DB record is available. Source: "(null)". HResult: 0x80040E14
Hi, below is the query that i use.update user set user_description=' "+ userDesc +" ' where user_id = 1;userDesc is the value taken from a textbox and is supposed to be used with the update query.userDesc = "kad'nsad'kasnd'nak";The quotes in userDesc is affecting the update. Is there anyway to replace quotes with ' using stringbuilder?
I was having some issues with converting this @BeginDate(which is passed in as a datetime) correctly and someone suggested the syntax below. It enloses it in triple single quotes. That seemed to work, but it also seems to work with single quotes too. Can someone explain the use of triple single quotes in stored procedures?
I have 2 SQL 6.5 databases on separate servers. Server A replicates a text field into a table on server B.
On server A the field contains text similar to THIS IS FRED'S HOUSE. After replication to Server B it looks like THIS IS FRED''S HOUSE. The distribution database also has it as THIS IS FRED''S HOUSE. Using ODBC trace I cannot see the value being passed in the text field as it is displayed as a question mark e.g. ?.
I have to use bcp to import two text files everyday for database update. The problem is that some of the character fields that are being imported have double-quotes and/or commas in them. When these are imported into the SQL Server tables additional double quotes are being added into these strings.
I`m new to sql and am having trouble with updates. I`m trying to make a web page where people can enter text and have it submitted to the database. The problem is that I need to let people submit text with quotes (single and double). When my cgi generates the sql, the quotes cause problems with the dbms (ie. in the statement:
UPDATE mytable SET thetext = `This is Joe`s text.` WHERE user = `joe`
the apostraphy in "joe`s" is interpreted as meaning the end of the string to enter into "thetext" ). I expect that there`s some escape character that I don`t know about? I know this is a very basic question, but any help would be greatly appreciated.
I have a CSV with some columns containing quoted text with the text itself containing quotes.
I'm trying to use a Flat File Source in SSIS. I've set a double quote as the text qualifier (") and comma as the delimiter. The trouble I'm having is getting to text that contains a double quote like in the following example;
123,"xyz","Don't you hate when MS say's it's a "feature" and not a bug","more data"
SSIS is seeing the first quote as a text qualifier and the second quote as the end of the text. Because the next delimiter is not found (in this case a comma), it returns;
[staging_output [4195]] Error: The column delimiter for column "Column 3" was not found.
How I can get SSIS to treat the whole column as a single piece of text that just happens to contain quotes?
I am having a problem with updating a password within a table. Below is the old and new password that needs to be updated. Old2"3("-"3#@(%P="''_DD@D* New :"I+)#]*1#E,%R-''7^,TEA$X&^O_-68DIK,@
Below is the query that I am trying to run. I believe my problem is becuase of the Single Quotes found within both the old and new password.
I have tried to escape the single quotes, @local_variable, CHAR(39) and other ways of playing with the string. I cannot seem to find a solution.
If you were to ignore the update statement, the SELECT statement would return no results even though the PRINT statement displays the required data. This is what baffles me and why I cannot run the UPDATE statement, becuase of course, nothing would be updated since no results were returned.
-- 2"3("-"3#@(%P="''_DD@D* ///// The old password.
SET @OLD_PASSWORD = '2"3("-"3#@(%P="' + CHAR(39) + CHAR(39) + '_DD@D*'
-- :"I+)#]*1#E,%R-''7^,TEA$X&^O_-68DIK,@ ///// The new password.
SET @NEW_PASSWORD = ':"I+)#]*1#E,%R-' + CHAR(39) + CHAR(39) + '7^,TEA$X&^O_-68DIK,@'
PRINT @OLD_PASSWORD PRINT @NEW_PASSWORD
SELECT * FROM Credentials WHERE Is_Active = 1 AND [Password] = @OLD_PASSWORD
/* Attempt to update the password table. */ UPDATE Credentials SET [Password] = @NEW_PASSWORD WHERE [ID] IN (SELECT [ID] FROM Credentials WHERE Is_Active = 1 AND [Password] = @OLD_PASSWORD )
This is what the crystal reports makes, when you enter the tables and link. I also have some sql that i pasted there without the quotes. THey both run. Only isssue I have is that my sql which is a view does not update on demand from the server. IOW, they enter a new row. and it's not immediatlyin the crystal report. I asked the user if he can logout and back in and he says that he doesn't have to do that with other crystal reports.
SELECT "OEIND94"."IDDOCD" AS INV_DATE, "OEIND94"."IDORD#" AS ORD_NUM, "OEIND94"."IDORDT" AS ORD_TYPE, "OEIND94"."IDPRLC" AS PROD_FAMILY, "OEIND94"."IDPR$C" AS PRICE_CODE, "OEIND94"."IDCOM#",
Hi,It seems to be simple, however, it stumbles me.how to replace all the double quotes (") within the followingsentence (or a column) with single quotes ('),colA = this is a freaking "silly" thing to dointocolA this is a freaking 'silly' thing to doSelect Replace(colA,'"',''')[color=blue]>From tblXYZ[/color]won't work,Select Replace(colA,'"',"'")[color=blue]>From tblXYZ[/color]won't work neither.How come? Thanks.
I have been searching for an escape character or a way of escapingdouble quotes that are actually in a string that I am using in thecontains predicate.Here is an exampleselect *from tablewhere contains(field, '"he said "what is wrong", that is what hesaid"')I need the double quotes in the string because they are part of thetext. Of course, Fulltext search raises the errorServer: Msg 7631, Level 15, State 1, Line 1Syntax error occurred near 'what is wrong", that is what he said'.Expected ''''' in search condition '"he said "what is wrong", that iswhat he said"'.If I remove the double quotes, the search does not return the properresults.Thanks in advance for the helpBill
Hi i am importing data from table to flat file(csv). i have two problems 1. if a column has commas(,) it should not create a new column i.e the column in csv file can have commas 2.if a column has double quotes then csv file column should have double quotes. please help me.I am using derived column I dont know how to search double quotes in string.
I have written a little bit of VB.NET code that basically takes three strings, transforms them, and returns a single string to be stored in my table.
I am running into a strange problem, however... for some reason, a number of my processed rows are missing a pair of double quotes (").
The vast majority of the records are formatted properly, and have the double quotes in the expected locations.
The most frustrating thing about it is that I have included the offensive input strings in my Test.sql test script, and when I step through the entire routine, the return value is perfect...
i apologize for being the worst ever at posting questions here, please let me know if i can add anything
I have a lot of data coming in from CSV files. I have many CSV files (~20), with varying amounts of data- but some are quite large (largest file is ~230mb)
I'm trying to import it into a SQL database via SSIS, but the data is a little bit frustrating.
Many things to notice here - as well you can imagine some of the difficulties here.
After parsing, this data should have 4 columns-
Column1 Column2 Column3 Column4
Text From Vendor "Vendor Name, Inc." blah blah Next string <blank> 1234
The biggest problems stem from the double quotes mixed in with the comma because it is a comma delimited file with quotes as the text qualifier. The other problem is the double quotes with blank text ... which prevents me from doing a replace on the double quotes ... I think ...
What would be your suggestions to help me parse this out? (don't forget, some of these are large files with about 260,000 records- )
When users enter text into a textbox, to be INSERTed into my table, SQL Server throws an error if their text contains a single quote. For example, if they enter "It's great!" then it causes this error:Error: Incorrect syntax near 's'. Unclosed quotation mark after the character string ''. How can I allow text with single quotes to be inserted into the table?
My code results in SQL statements like the following one - and it gives an error because of the extra single-quotes in 'it's great': UPDATE Comments SET Comment='it's great' WHERE UserID='joe' AND GameID='503' Here's the error I get when I try this code in SQL Server: Msg 102, Level 15, State 1, Line 1Incorrect syntax near 's'.Msg 105, Level 15, State 1, Line 1Unclosed quotation mark after the character string ''. I need to know how I can insert a string such as 'it's great' - how do I deal with the extra quotes issue? is there a way to ecape it like this 'it/'s great' ? This doesn't seem to work. Here's the code that generates the SQL. I'm using a FCKeditor box instead of a TextBox, but I got the same error when I was using the TextBox: string strUpdate = "UPDATE Comments SET Comment='";strUpdate = strUpdate + FCKeditor1.Value;//strUpdate = strUpdate + ThisUserCommentTextBox.Text;strUpdate = strUpdate + "' WHERE UserID='";strUpdate = strUpdate + (string)Session["UserID"];strUpdate = strUpdate + "'";strUpdate = strUpdate + " AND GameID='";strUpdate = strUpdate + Request.QueryString["GameID"];strUpdate = strUpdate + "'"; SqlConnection myConnection = new SqlConnection(...);SqlCommand myCommand = new SqlCommand(strUpdate, myConnection); try{myCommand.Connection.Open();myCommand.ExecuteNonQuery();}catch (SqlException ex){ErrorLabel.Text = "Error: " + ex.Message; }finally{myCommand.Connection.Close();}
I'm using SQL Server 2005 and ASP.NET 2.0 Much thanks
I'm trying to build a dynamic sql statement in a stored procedurre and can't get the like statement to work. My problem is with the single quote. for example LIKE '%@searchvalue%'. This works fine: select * from view_searchprinters where serialnumber like '%012%' But I can't figure out how to create this in a stored procedure. What syntax should I use for the line in bold?SET NOCOUNT ON;DECLARE @sn varchar(50)SET @sn = N'012'DECLARE @sql nvarchar(4000)SELECT @sql = 'select top 10 * from view_searchprinters' + ' WHERE 1 = 1 'SELECT @sql = @sql + ' 'IF @sn IS NOT NULL SELECT @sql = @sql + 'and serialnumber LIKE ''' + '%' + '@sn' + '%' + ''' 'EXEC sp_executesql @sql, N'@sn varchar(50)', @sn
Normally when I do a sort for a stored procedure I use something like this:
ORDER BY CASE WHEN @SortOrder = 'FirstName' THEN FirstName WHEN @SortOrder = 'LastName' THEN LastName WHEN @SortOrder = 'Extension' THEN Extension ELSE LastName
How do I get that into a dynamic SQL statement with proper quotes? Most of the SQL left out for cleanliness. The order by below would be the ELSE condition.
I am trying to build a dynamic where statement for my sql stored prcoedure if len(@Office) > 0 select @strWhereClause = N'cvEh.chOfficeId in (select id from dbo.csfParseDeLimitedText( ' + @vchOffice + ',' + ''',''' + '))' + ' and ' + @strWhereClause In this case users can enter comma delimited string in their search criteria. So if they enter we1, we2, we3 then my sql statement should look like select @strWhereClause = cvEh.chOfficeId in (select id from dbo.csfParseDeLimitedText('we1', 'we2', 'we3'),',') My csfParseDeLimitedText function looks like this Create FUNCTION [dbo].[csfParseDeLimitedText] (@p_text varchar(4000), @p_Delimeter char(1))RETURNS @results TABLE (id varchar(100))ASBEGIN declare @i1 varchar(200)declare @i2 varchar(200)declare @tempResults Table (id varchar(100))while len(@p_text) > 0 and charindex(@p_Delimeter, @p_text) <> 0beginselect @i1 = left(@p_text, charindex(@p_Delimeter, @p_text) - 1)insert @tempResults select @i1select @p_text = right(@p_text, len(@p_text) - charindex(@p_Delimeter,@p_text))endinsert @tempResults select @p_text insert @resultsselect *from @tempResultsreturnEND
My problem is it does not put quotes around the comma delimited stringso I want to put 'we1' , 'we2'. These single quotes are not coming in the dynamic sql statement. How can I modify my query so that single quotes around each entry should show up. Any help will be greatky appreciated. Thanks
I have a problem with inserting a string with single quotes. For instance, string testme = "we don't have anything"; insert into tableone (buff) values ("'" + testme + "'"); I get an error with the word "don't" with single quote. But if I delete the single quote "dont" then it inserts okay. Is is a bug in sql 2005? Please help. Thanks. blumonde