In my datedabase I have some customers with the next name: 't Woud.
The problem is the apostrophe in my query for my drill through.
This is my query:
SELECT DISTINCT c.alias AS Client, p.Alias AS Periode, u.alias as Product, v.alias as Verschil, CAST(s.indicatie AS decimal(6, 2)) AS Indicatie, CAST(s.realisatie AS decimal(6, 2)) AS Realisatie, CAST(s.real_indic AS decimal(6, 2)) AS [Realisatie -/- Indicatie], CAST(s.indicatie_fin AS decimal(6,0)) AS [Indicatie Fin], CAST(s.realisatie_fin AS decimal(6,0)) AS [Realisatie Fin], CAST(s.real_indic_fin AS decimal(6,0)) AS [Realisatie -/- Indicatie Fin]
FROM [BI_TZR].dbo.fact_clientsignaal s INNER JOIN
[BI_TZR].dbo.dim_verschil v ON s.verschil = v.verschil INNER JOIN
[BI_TZR].dbo.Dim_Periodewk p ON s.periode = p.Periode INNER JOIN
[BI_TZR].dbo.dim_client_uren c ON s.client_id = c.id INNER JOIN
[BI_TZR].dbo.dim_product u ON s.product = u.product
WHERE (LEFT(p.Alias, 1) = 'p') AND (c.alias like '%794735%') and s.kplts <> '1583'
ORDER BY s.product, s.periode
I try this:
SELECT DISTINCT replace ( c.alias, 'd', '') AS Client, this works, for the caracter D. But know I want it for the caracter apostrophe.
Can anyone tell me how to replace a single apostrophe in a record with a double apostrophe (in Query Analyzer, SQL7)? I've tried "select replace("d'","d'","d''")FROM RESORT" but it doesn't UPDATE the table.
heyi'm having a problem with a stored procedure, to cut a long story short i need to replace apostrophe's in my text, like soSET @prOtherValue = REPLACE(@prOtherValue,''', '''')this doesn't work thowhats the work aroundcheers!!!!
WHILE PATINDEX('%,%',@Columns)<> 0 BEGIN SELECT @Separator_position = PATINDEX('%,%',@Columns) SELECT @array_Value = LEFT(@Columns, @separator_position - 1) SET @FieldTypeID = (SELECT FieldTypeID FROM [Form].[Fields] WHERE FieldID = (CAST(@array_Value AS INT))) SET @FieldName = (SELECT [Name] FROM [Form].[Fields] WHERE FieldID = @array_Value) print 'arry value' + CONVERT(VarChar(500), @array_value) print 'FieldTypeID: ' + CONVERT(VARCHAR(500), @FieldTypeID) PRINT 'FieldName: ' + @FieldName
BEGIN IF @FieldTypeID = 1 OR @FieldTypeID = 2 OR @FieldTypeID = 3 OR @FieldTypeID = 9 OR @FieldTypeID = 10 OR @FieldTypeID = 7 BEGIN SET @InnerItemSelect = ' (SELECT ISNULL(CONVERT(VARCHAR(MAX),[Value]),'''') FROM [Item].[ItemDetailFieldRecords] IDFR WHERE IDFR.ItemDetailID = ID.ItemDetailID AND IDFR.FieldID = ' + @array_Value + ') AS ''' + @FieldName + ''' ' SET @InnerTaskSelect = ' (SELECT ISNULL(CONVERT(VARCHAR(MAX),[Value]),'''') FROM [Item].[TaskFieldRecords] TFR WHERE TFR.TaskID = T.TaskID AND TFR.FieldID = ' + @array_Value + ') AS ''' + @FieldName + ''' ' END ELSE IF @FieldTypeID = 4 OR @FieldTypeID = 8 --DropDownList/RadioButtonlist BEGIN SET @InnerItemSelect = ' (SELECT [Value] FROM [Form].[FieldListValues] FFLV INNER JOIN [Item].[ItemDetailFieldListRecords] IDFLR ON FFLV.FieldListValueID = IDFLR.FieldListValueID WHERE IDFLR.ItemDetailID = ID.ItemDetailID AND FFLV.FIeldID = ' + @array_value + ') AS ''' + @FieldName + ''' ' SET @InnerTaskSelect = ' (SELECT [Value] FROM [Form].[FieldListValues] FFLV INNER JOIN [Item].[TaskFieldListRecords] TFLR ON FFLV.FieldListValueID = TFLR.FieldListValueID WHERE TFLR.TaskID = T.TaskID AND FFLV.FIeldID = ' + @array_value + ') AS ''' + @FieldName + ''' ' END ELSE IF @FieldTypeiD = 5 --Cascading BEGIN SET @InnerItemSelect = ' (SELECT [FCV].[Value] FROM [Form].[FieldCascadingValues] FCV INNER JOIN [Form].[FieldCascadingLookUpTables] LT ON FCV.FIeldCascadingLookupTableID = LT.FieldCascadingLookupTableID INNER JOIN [Item].[ItemDetailFieldCascadingRecords] IDFCR ON IDFCR.FieldCascadingValueID = FCV.FieldCascadingValueID WHERE IDFCR.ItemDetailID = ID.ItemDetailID AND LT.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' ' SET @InnerTaskSelect = ' (SELECT [FCV].[Value] FROM [Form].[FieldCascadingValues] FCV INNER JOIN [Form].[FieldCascadingLookUpTables] LT ON FCV.FIeldCascadingLookupTableID = LT.FieldCascadingLookupTableID INNER JOIN [Item].[TaskFieldCascadingRecords] TFCR ON TFCR.FieldCascadingValueID = FCV.FieldCascadingValueID WHERE TFCR.TaskID = T.TaskID AND LT.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' ' END ELSE IF @FieldTypeiD = 6 --ListBox BEGIN SET @InnerItemSelect = ' (SELECT i.[CSV] FROM @ItemDetailLV i WHERE i.ID = ID.ItemDetailID AND i.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' ' SET @InnerTaskSelect = ' (SELECT it.[CSV] FROM @TaskLV it WHERE it.ID = T.TaskID AND it.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' ' END ELSE IF @FieldTypeID = 11 --Users BEGIN SET @InnerItemSelect = ' (SELECT SU.[UserID] FROM [Security].[Users] SU INNER JOIN [Item].[ItemDetailUserRecords] IDUR ON SU.UserID = IDUR.UserID WHERE IDUR.ItemDetailID = ID.ItemDetailID AND IDUR.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' ' SET @InnerTaskSelect = ' (SELECT SU.[UserID] FROM [Security].[Users] SU INNER JOIN [Item].[TaskUserRecords] TUR ON SU.UserID = TUR.UserID WHERE TUR.TaskID = T.TaskID AND TUR.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' ' END ELSE IF @FIelDTypeID = 12 --Group BEGIN SET @InnerItemSelect = ' (SELECT SG.[GroupID] FROM [Security].[Groups] SG INNER JOIN [Item].[ItemDetailGroupRecords] IDGR ON SG.GroupID = IDGR.GroupID WHERE IDGR.ItemDetailID = ID.ItemDetailID AND IDGR.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' ' SET @InnerTaskSelect = ' (SELECT SG.[GroupID] FROM [Security].[Groups] SG INNER JOIN [Item].[TaskGroupRecords] TGR ON SG.GroupID = TGR.GroupID WHERE TGR.TaskID = T.TaskID AND TGR.FieldID = ' + @array_value + ') AS ''' + @FieldName + ''' ' END END PRINT 'Inner Item Select:' + @InnerItemSelect PRINT 'Inner Task Select:' + @InnerTaskSelect SET @IDSelect = @IDSelect + @InnerItemSelect + ', ' SET @TSelect = @TSelect + @InnerTaskSelect + ', ' SELECT @Columns = STUFF(@Columns, 1, @separator_position, '')
END
---------------
That is only part of a large query that writs a SQL Query to a column in a Database. That Query (in the column) is just ran normally so I don't need to compile it each time I want to run it.
THe problem I have is @FieldName might be: ryan's field.
That apostrophe is killing me because the SQL keeps it as ryan's field, not ryan''s field(note the 2 apostrophes). I cannot do: REPLACE(@FieldName, ''', '''') because it's not closing the apostrophes. Is there an escape character that I can use to say only one: ' ?
I tried:
DECLARE @t VARCHAR(500) SET @t = (SELECT [Name] FROM [Form].[Fields] WHERE FieldID = 1) print @t -- @t will print: Ryan's Field PRINT QUOTENAME('' + @t + '', '''')
but that gives me: 'Ryan''s Field'
Any help would rock. If I make any changes to the way this field is input into the DataBase, I know I will need to do a lot of re-work in many spots. WHich is why i'm trying to solve this on the SQL side.
I made a stored proc for update fields in a table everything is correct but when my new field contains a special caracter like *,/,[, ' , and a space too i have an error. I wrote it and i don't understand why it doesn't work.
Hello I am newbies with SQL 2005 I want install Windows sharepoint services 3 in french on my SBS 2003 R2 SP2 also in frecnh langage and at the end of the install, a message say to me : Bin caracter are not accepted in your configuration SQL Langage is not correct (I have French_CS_AS)
Where is possible to change these parameters ? I try to find but never find Thank You in advance for your help
++ Michel If you have the answer in French it's better for me but not neccessary !
i'm using delphi 7 and have a query in which i'm trying to find namesthat have an apostrophe in them, i.e. "o'mally". my problem is thatwhen i write my select statement i can't get the quotes right. i getall types of errors no matter what i try. i get "missing right quote","invalid token" etc. i've tried using QuotedStr and nothing works.here is my current attempt in which i get an "invalid use of keyword.token: n'%'"sSQL := 'SELECT statenotified, notary_id, LastName, FirstName,' +' MiddleInitial, Indep, Book_number, Page_number,' +' CloseRec, TermBegins, TermEnds, DatePickedUp,FailedToQualify,' +' Notes, SOSLtrSent FROM notaries WHERE LastName LIKE '''+''+ edtLastName.Text+'+''%'' AND CloseRec = 1 order bylastname';
Hi Friends, I have stored names with ' s (Apostrophes) and without 's in the database(sqlserver).Example:O'Relly I tried to get the values with select statement like Dim str As String = Request.QueryString("Title") Dim query As String = "SELECT * FROM Test where title like '" + str + "'" Problem is getting the all the values from database except O'Relly just getting O other word Relly no..... What should do I and what code do I need ..?
I tried with the below code also Dim x As Long For x = 1 To Len(str) If Mid$(str, x, 1) = "'" Then str = str & "''" Else str = str & Mid(title1, x, 1) End If Next
I need help with a simple query. We have 86 entries with the City of O'Fallon in our db. How do I do this with the apostrophe in O'Fallon? Below is just to give an idea of what I want. Thanks. SELECT * FROM Organization WHERE City=O'Fallon
Ok, I still have some uncertainty as to just exactly how this whole apostrophe thing works with databases. I understand that it is a reserved character and so when a sql query runs into one of these creatures it looks at it as something other than a normal character.
I am working primarily in vb/asp/sql server with a little bit of access. I am familiar with the instrinsic 'Replace' function and I use it but I still have occassional problems.
I would like any information I can get on just exactly why/how this thing works and how to work-around the apostrophe when writing to, reading from, and validating data from sql server/access/any databases.
I am having weird trouble with READING data from my Access database where the field has an apostrophe - but only when I display the field in a textbox.
For example, the field "Don't do this" becomes "Don" when my SQL query outputs the result:
OK so I need to use a dynamic SQL statement in a SqlDataSource object because I need to pass in the column name. I'm having trouble accounting for the apostophes I have to interpret literals within the statement. This is connecting to an Oracle database. This is what I originally tried... <asp:SqlDataSource ID="SqlDataSourceMine" runat="server" ConnectionString="<%$ ConnectionStrings:My_Connection_String %>" ProviderName="<%$ ConnectionStrings:My_Connection_String.ProviderName %>" SelectCommand="SELECT m.YIE, :selecteditem, m.ENDTIME FROM MyMAP.MAP_M_SUM m WHERE (m.GROUPID LIKE 'YC%' AND m.GROUPID NOT LIKE 'YCX%' AND m.ENDTIME >= SYSDATE-14)"> <SelectParameters> <asp:ControlParameter Name="selecteditem" ControlID="itemlabel" PropertyName="Text" Type="String" /> </SelectParameters></asp:SqlDataSource> And the second column returned as :selecteditem for the column name and the value of itemlabel.text (what I wanted to be the column that was queried) as the value in each of the rows of that column. So I tried dynamic SQL to put the value of itemlabel.txt as the column to be queried, but I'm not sure how to get the query to read the literals. How can I accomplish this? <asp:SqlDataSource ID="SqlDataSourceMine" runat="server" ConnectionString="<%$ ConnectionStrings:My_Connection_String %>" ProviderName="<%$ ConnectionStrings:MY_Connection_String.ProviderName %>" SelectCommand="EXEC('SELECT m.YIE, '+selectedbin+', m.ENDTIME FROM MMAP.MAP_M_SUM m WHERE (m.GROUPID LIKE '+paramlike+' AND m.GROUPID NOT LIKE '+paramnotlike+' AND m.ENDTIME >= SYSDATE-14)')"> <SelectParameters> <asp:ControlParameter Name="selectedbin" ControlID="binlabel" PropertyName="Text" Type="String" /> <asp:ControlParameter Name="paramlike" ControlID="Label1" PropertyName="Text" Type="String" /> <asp:ControlParameter Name="paramnotlike" ControlID="Label2" PropertyName="Text" Type="String" /> </SelectParameters></asp:SqlDataSource> This errors to "illegal variable name" Can someone help me out please? Thanks a lot. -steve
Hi all,I am not sure this question will belong to a sql group or .net.but the problem I have is, my data entry forms crashes when some enter a apostrophe character in one of the field. that field is of type varchar in sql server 2000.for ex, Ryan O'neill will crash the application. I have a drop down list of all my crew names in my form.what should I need to do to allow user to add apostrophe and not to have application crash?Please help it is very urgent.Thank You,
The end result: I need one of the columns in my result set (col2) to have a preceeding apostrophe (i.e., '001234 ).
The problem: I am building my query as a string and then using the EXEC() function to execute it. For example: SET @strSQL = 'SELECT col1, col2 FROM mytable' EXEC(@strSQL)
Just to tame any answers that might not be directed to the specific question, the query Must be built as a string and then executed.
I have been unable to obtain the solution and I am wondering if it is even possible?
Hi, i'm having problems executing the followingSET @SQLAH = 'SELECT sub_id WHERE 'SET @SQLAH = @SQLAH + 'VENUE_TYPE = Hotel'EXEC(@SQLAH)Its getting stuck at Hotel. I realise that it should include an apostrophe either side like so:..SET @SQLAH = @SQLAH + 'VENUE_TYPE = 'Hotel' '..But this escapes the string, how would i escape an apostrophe in a string?I thought maybe:SET @SQLAH = @SQLAH + 'VENUE_TYPE = 'Hotel' 'But no joy :confused: Thanks
I am having a problem trying to pull data that has apostrophe in them. How can I do this? I get this as an error
Msg 105, Level 15, State 1, Line 14 Unclosed quotation mark after the character string ''.
Select Name From Table Where Name IN (CHILDREN'S ANES ASSOCS-CHOP,CHILDREN'S HEALTHCARE-CHOP,CHILDREN'S PSYCH ASSOC-CHOP,CHILDREN'S SURGICAL ASSOC-CHOP)
Getting an error when i execute the query. select * from trio where ad_str1 like '%''
Server: Msg 105, Level 15, State 1, Line 1 Unclosed quotation mark before the character string '%' '. Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near '%' '.
How can I insert ' (Apostrophe) into sql table field ? Insert Into Table(Field) Values(?) After executing sql statement above, I want to see ' (apostrope) in field. Thanks
Hello, I'm using Visual Basic 6 to insert data into SQL Server 2000 via a stored procedure. Apostrophes are giving me problems. Using T-SQL it works fine.
Following is the code: ======================= cn.ConnectionString = "Driver=" & cnDriver & ";Server=" & cnServer & ";Database=" & cnDatabase & ";UID=" & cnUID & ";PWD=" & cnPWD cn.Open
'TURNING QUOTES OFF allows a literal string to be delimited by double quotes and to accept an apostrophe 'cn.Execute "SET QUOTED_IDENTIFIER OFF" (This works using T-SQL statements only)
'set the reference to the ADO Command object Set cmd = New ADODB.Command
'Set the command object properties Set cmd.ActiveConnection = cn
The above works great as long as the pDocClass field does not contain an apostrophe. In the stored procedure, pDocClass is defined as @pDocClass char (40). Following is the error I receive: "Line 1: Incorrect syntax near '{'
Any help with handling an apostrophe in the CommandText above would be greatly appreciated!
I have a insert statement but one of the strings contains a apostrophe. If I leave the apostrophe in an error occurs becuase it thinks that it is the end of the string. What is the proper syntax for including apostrophes in a string?
We just encountered an odd failure in ADODB. If it gets an SQL query with a comment embedded in it, and the comment has an apostrophe as one of the characters, ADODB gets confused as it tries to plug in parameters for placeholders later in the query. For example:
SELECT id, name
FROM doc_type /* this won't work! */
WHERE name LIKE ?
If you take out the apostrophe ("this will not work!") or move the comment to follow the placeholder, the query works.