dynamic-sql

Dynamic SQL Comma-Delimited Value Query

我是研究僧i 提交于 2019-12-01 06:04:44
问题 [Update: Using SQL Server 2005] Hi, what I want to do is query my stored procedure with a comma-delimited list of values (ids) to retrieve rows of data. The problem I am receiving is a conversion error: Conversion failed when converting the varchar value ' + @PassedInIDs + ' to data type int. The statement in my where-clause and error is: ... AND (database.ID IN (' + @PassedInIDs + ')) Note: database.ID is of int type. I was following the article at: http://www.sql-server-helper.com/functions

How can I replace all key fields in a string with replacement values from a table in T-SQL?

微笑、不失礼 提交于 2019-12-01 05:47:37
问题 I have a table like: TemplateBody --------------------------------------------------------------------- 1.This is To inform #FirstName# about the issues regarding #Location# Here the key strings are #FirstName# and #Location# which are distinguished by hash tags. I have another table with the replacement values: Variables | TemplateValues ----------------------------- 1.#FirstName# | Joseph William 2.#Location# | Alaska I need to replace these two key strings with their values in the first

How to make dynamic pivot in oracle PL SQL

一曲冷凌霜 提交于 2019-12-01 05:22:32
问题 I have a query below: And I want to make this pivot dynamic in procedures SELECT * FROM ( SELECT tcsd AS Aggregator, country, SUM (COUNT) AS total, COUNT (dest_addr) AS bnum, time_stamp FROM t_raw_intl_sms_aggr GROUP BY tcsd, COUNT, country, time_stamp ORDER BY tcsd, COUNT, country, time_stamp) PIVOT (SUM (total) AS total, COUNT (bnum) AS bnum_total FOR time_stamp IN (TO_DATE ('20150801', 'yyyymmdd') AS DAY_20150801_TOTAL, TO_DATE ('20150802', 'yyyymmdd') AS DAY_20150802_TOTAL, TO_DATE (

EXECUTE of SELECT … INTO is not implemented

老子叫甜甜 提交于 2019-12-01 05:11:26
I am trying to run this function in PostrgeSQL: CREATE OR REPLACE FUNCTION create_partition_and_insert() RETURNS trigger AS $BODY$ DECLARE partition VARCHAR(25); _date text; BEGIN EXECUTE 'SELECT REPLACE(' || quote_literal(NEW.date) || ',''-'',''_'') into _date'; partition := TG_RELNAME || '_' || _date || ‘p’; IF NOT EXISTS(SELECT relname FROM pg_class WHERE relname=partition) THEN RAISE NOTICE 'A partition has been created %',partition; EXECUTE 'CREATE TABLE ' || partition || ' (check (date = ''' || NEW.date || ''')) INHERITS (' || TG_RELNAME || ');'; END IF; EXECUTE 'INSERT INTO ' ||

Oracle EXECUTE IMMEDIATE into a cursor

拜拜、爱过 提交于 2019-12-01 04:34:22
I have a stored procedure which used the EXECUTE IMMEDIATE command to execute a very long string. How do I support a very long string and return the data into a refcursor? Assuming that your SQL is not longer than 32K (as @Tony Andrews hinted at), you should be able to use something like this: declare SQL_Text varchar2(32760) := 'select * from dual'; --your query goes here cur sys_refcursor; begin open cur for SQL_Text; end; When working with Ref Cursors, open-for can be used directly, instead of execute immediate . 来源: https://stackoverflow.com/questions/4714163/oracle-execute-immediate-into

SQL Dynamic SELECT statement from values stored in a table

只谈情不闲聊 提交于 2019-12-01 04:18:08
问题 I have been researching this for a couple of days and feel like I am going around in circles. I have basic knowledge of SQL but there are many areas I do not understand. I have a table that stores the names and fields of all the other tables in my database. tblFields =================================================== TableName FieldName BookmarkName --------------------------------------------------- Customer FirstName CustomerFirstName Customer LastName CustomerLastName Customer DOB

Using dynamic SQL in an OLE DB source in SSIS 2012

こ雲淡風輕ζ 提交于 2019-12-01 03:02:55
问题 I have a stored proc as the SQL command text, which is getting passed a parameter that contains a table name. The proc then returns data from that table. I cannot call the table directly as the OLE DB source because some business logic needs to happen to the result set in the proc. In SQL 2008 this worked fine. In an upgraded 2012 package I get "The metadata could not be determined because ... contains dynamic SQL. Consider using the WITH RESULT SETS clause to explicitly describe the result

MySQL join tables where table name is a field of another table

社会主义新天地 提交于 2019-12-01 02:13:45
问题 I have 5 tables. One primary and 4 additional (they have different columns). objects obj_mobiles obj_tablets obj_computers Here is the structure of my main table (objects). ID | type | name | etc... So what I want to do is to join objects with other (obj_mobiles,obj_tablets,...) tables, depending on type field. I know that I should use dynamic SQL. But I can't make procedure. I think it should look like something like this. SELECT objects.type into @tbl FROM objects; PREPARE stmnt FROM

EXECUTE of SELECT … INTO is not implemented

血红的双手。 提交于 2019-12-01 02:09:18
问题 I am trying to run this function in PostrgeSQL: CREATE OR REPLACE FUNCTION create_partition_and_insert() RETURNS trigger AS $BODY$ DECLARE partition VARCHAR(25); _date text; BEGIN EXECUTE 'SELECT REPLACE(' || quote_literal(NEW.date) || ',''-'',''_'') into _date'; partition := TG_RELNAME || '_' || _date || ‘p’; IF NOT EXISTS(SELECT relname FROM pg_class WHERE relname=partition) THEN RAISE NOTICE 'A partition has been created %',partition; EXECUTE 'CREATE TABLE ' || partition || ' (check (date

Dynamic SQL - Check syntax and semantics

帅比萌擦擦* 提交于 2019-12-01 00:33:52
With Oracle dynamic SQL one is able to execute a string containing a SQL statement. e.g. l_stmt := 'select count(*) from tab1'; execute immediate l_stmt; Is it possible to not execute l_stmt but check that the syntax and semantics is correct programmitically? EXPLAIN PLAN will check the syntax and semantics of almost all types of SQL statements. And unlike DBMS_SQL.PARSE it will not implicitly execute anything. The point of the explain plan is to show how Oracle will execute a statement. As a side-effect of generating the plan it must also check syntax, privileges, and generally do everything