SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL INSERT command problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MarjanMM
Starting Member

4 Posts

Posted - 09/27/2012 :  07:37:46  Show Profile  Reply with Quote
Hello everyone,
I am trying to INSERT a command in my table but I have a problem. The command has to be exactly like this:

SELECT Value FROM OPENQUERY (iHistorian,'SELECT * FROM ihRawData WHERE TagName LIKE *DEM_S01_N and SamplingMode=CurrentValue')[i]

This command I have to insert into the table name SQLLIB (sqlname, sqlcmd):

INSERT INTO sqllib
VALUES ('CMD1', 'SELECT Value FROM OPENQUERY (iHistorian,'SELECT * FROM ihRawData WHERE TagName LIKE *DEM_S01_N and SamplingMode=CurrentValue');')

The problem is is with the quote ' in my command. How can I get my command into the table?

Best regards

Edited by - MarjanMM on 09/27/2012 08:09:27

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 09/27/2012 :  07:50:16  Show Profile  Visit webfred's Homepage  Reply with Quote
Inside single quotes you can escape single quotes by a second single quote.

'SELECT Value FROM OPENQUERY (iHistorian,''SELECT * FROM ihRawData WHERE TagName LIKE *DEM_S01_N and SamplingMode=CurrentValue'');'


Too old to Rock'n'Roll too young to die.
Go to Top of Page

MarjanMM
Starting Member

4 Posts

Posted - 09/27/2012 :  08:15:26  Show Profile  Reply with Quote
Sorry for the wrong topic name,

I have tryed with second single quote, but I get an error:

Cannot process the object "'SELECT * FROM ihRawData WHERE TagName LIKE *DEM_S01_N and SamplingMode=CurrentValue'". The OLE DB provider "IhOLEDB.iHistorian" for linked server "iHistorian" indicates that either the object has no columns or the current user does not have permissions on that object.
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 09/27/2012 :  08:40:57  Show Profile  Visit webfred's Homepage  Reply with Quote
Please show the statement that gives the posted error.


Too old to Rock'n'Roll too young to die.
Go to Top of Page

MarjanMM
Starting Member

4 Posts

Posted - 09/27/2012 :  08:52:23  Show Profile  Reply with Quote
Sorry, I have made a mistace. Now it is OK.
Thank you very much
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 09/27/2012 :  08:53:50  Show Profile  Visit webfred's Homepage  Reply with Quote
fine


Too old to Rock'n'Roll too young to die.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000