There is a single quote in insert script. Like 'JOHN'S' , Is there any other way to insert it except using Concat and two times single quote in Sybase.
Like 'JOHN''S'.
As I am able to handle it in oracle like q'(JOHN'S)'. Is there any function to handle this in sybase.
Related
I am attempting to insert a SAS dataset into an existing table on a SQL Server. This is via a simple proc sql statement.
proc sql;
insert into Repo.Test_Table
select * from Work.MetaTable;
quit;
One of the fields, [Method], is not inserting into the SQL table as expected. The [Method] field in the SAS table contains several brackets and other punctuation so I think this is causing a problem. For example, the Work.MetaTable looks like this:
Field_ID
Method
1
([Field_1]<=[Field_8])
2
([Field_4]=[Field_5])
When I run the proc sql to insert this into SQL, it only inserts the first open bracket "(" and this is the case for every row. For example, those two rows look like this in the SQL table:
Field_ID
Method
1
(
2
(
The [Method] field in SQL is nvarchar(max).
Does anyone know what might be causing the issue here and how I can get around it?
I used OPENROWSET to insert excel file into table
INSERT INTO [Program_2].[dbo].[Current]
([Div],[Date],[HomeTeam],[AwayTeam])
SELECT [Div],[Date],[HomeTeam],[AwayTeam]
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\Users\2016-2017.xls', [B1$])
But if a [B1$] sheet does not exist I don't know how to skip that table and insert another table for exaple [D1$]. I try using EXISTS but I have no luck
Newer Sql servers I believe support a "try" command. That may be an easy way to get through what you are trying to do. This would cause the Sql sever to try to write to the page that does not exist, fail, but allow your code to continue.
I'm doing queries in which I want to extract the left-most n characters from a string that has been stripped of all leading and following spaces. An example is:
Select SUBSTRING(LTRIM(RTRIM(somefield)), 0, #n) AS mydata
FROM sometable
It's the only way I can figure to do it on a SQL Server.
I've never written a UDF before, but I think if I was just working on a SQL Server, I could create a user-defined function such as:
CREATE FUNCTION udfLeftTrimmed
(
#inputString nvarchar(50),
#n int
)
RETURNS nvarchar(#n)
AS
BEGIN
RETURN SUBSTRING(LTRIM(RTRIM(#inputString)), 0, #n);
END
I could then do something like:
Select udfLeftTrimmed(somefield,6) AS mydata
FROM sometable
which is at least a little easier to read and understand.
The question is, how do I create the UDF in ColdFusion? All my searches for SQL user-defined function in ColdFusion just gave me how to create ColdFusion functions.
Since there is nothing special or "dynamic" about your UDF you really don't need to create it in CF. You should just create it using MSSQL Manager. UDFs in SQL are like stored procedures. Once created they are a part of the DB/Schema. so create once, use as many times as you like (as #leigh has mentioned).
Keep in mind that using a SQL udf in SQL usually requires the user prepend as in:
<cfquery...>
Select dbo.udfLeftTrimmed(somefield,6) AS mydata
FROM sometable
</cfquery>
Note the "dbo.udf..." that dbo is important and may be why your subsequent try is failing - besides getting a duplicate UDF error by now. :)
NOTE:
To follow up on your comments and Leighs, you can create your UDF in a DB accessible to your user then access it as dbo.dbname.function ... as inthe following code:
<cfquery...>
Select dbo.myspecialDatabase.udfLeftTrimmed(somefield,6) AS mydata
FROM sometable
</cfquery>
Then you need only create it one time.
So I seem to be forced to use MS Access as a SQL Server client.
For whatever reason, this just won't execute:
INSERT INTO l9990064_INF_PATH (DATA_PATH)
VALUES ("/OlifeRequest/RequestType")
SELECT DATA_PATH, "/OlifeRequest/RequestType"
FROM l9990064_INF_PATH
WHERE DATA_PATH NOT IN
(SELECT DISTINCT DATA_PATH
FROM l9990064_INF_PATH
WHERE DATA_PATH="/OlifeRequest/RequestType");
Basically the query attempts to insert a field in table if it doesn't already exist in that table.
The error I get is:
Missing semicolon (;) at end of SQL statement.
Clearly this is not the case, there is in fact a semicolon at the very end.
It appears to be a valid query so I'm wondering what I have to do here? Thanks!
INSERT INTO l9990064_INF_PATH (DATA_PATH)
VALUES ('/OlifeRequest/RequestType'); --<-- Single Quotes
SELECT DATA_PATH, '/OlifeRequest/RequestType' --<-- Single Quotes
FROM l9990064_INF_PATH
WHERE DATA_PATH <> '/OlifeRequest/RequestType'; --<-- Single Quotes
Also there is no need to use NOT IN operator since it is checking the value in the same table it is selecting from.
Or if you were trying to insert data from a SELECT statement , it would be something like ....
INSERT INTO l9990064_INF_PATH (DATA_PATH, Other_Column_Name)
SELECT DATA_PATH, '/OlifeRequest/RequestType'
FROM l9990064_INF_PATH
WHERE DATA_PATH <> '/OlifeRequest/RequestType';
I didn't know this at first, but it appears the queries I was using would work in SQL server but Access was only allowing Access queries or some shit. So even though Access was acting as a SQL server client, it wasn't really allowing me to use SQL server queries.
I went through the pain of getting SQL Server Management Studio as the client through the painful procurement at my company and I couldn't think of a better solution, do not use Access as a SQL Server client kids...
How this below insert query can be modified or escape single quote in SQL Server:
INSERT INTO <tblname> (title,desc)
VALUES
('Hen's Body','It's just best combination')
This query not run in SQL Server. I need similer solution to MySQL (like using backslash)as it is
INSERT INTO <tblname> (title,desc)
VALUES('Hen\'s Body','It\'s just best combination')
Regards
Double up the single quotes to escape them:
INSERT INTO ( title, description )
VALUES ( 'Hen''s Body', 'It''s just best combination' )