dynamic-sql

Cannot pass column name as parameter to sp_executesql

淺唱寂寞╮ 提交于 2019-12-22 08:15:02
问题 I'm having trouble executing the below piece of code, it's giving me an error as below: Msg 102, Level 15, State 1, Line 3 Incorrect syntax near '@ST'. I can try implementing the login using dynamic SQL, but wanted to try the sp_executesql method. Please let me know if I'm having some syntax error or I'm not supposed to pass table names as parameters? DECLARE @SQL NVARCHAR(4000)= ''; SET @SQL = N'--INSERT INTO #missingkeys ( SOURCE_KEY,[ROWCOUNT] ) SELECT S.[SOURCE_KEY], COUNT(1) AS [ROWCOUNT

exec sp_executesql @sql and exec (@sql) SQL Server

[亡魂溺海] 提交于 2019-12-21 08:59:39
问题 A Dynamic SQL query from lobodava is: declare @sql nvarchar(4000) = N';with cteColumnts (ORDINAL_POSITION, COLUMN_NAME) as ( select ORDINAL_POSITION, COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = N'''+ @tableName + ''' and COLUMN_NAME like ''' + @columnLikeFilter + ''' ), cteValues (ColumnName, SumValue) as ( SELECT ColumnName, SumValue FROM (SELECT ' + @sumColumns + ' FROM dbo.' + @tableName + ') p UNPIVOT (SumValue FOR ColumnName IN (' + @columns + ') )AS unpvt ) select row

ORA-01747: invalid user.table.column, table.column, or column specification

时光总嘲笑我的痴心妄想 提交于 2019-12-21 07:55:50
问题 Get the above error when the execute immediate is called in a loop Update CustomersPriceGroups set 1AO00=:disc Where cuno=:cuno Parameters: disc=66 cuno=000974 Update CustomersPriceGroups set 1AP00=:disc Where cuno=:cuno Parameters: disc=70.5 cuno=000974 Update CustomersPriceGroups set 1AQ00=:disc Where cuno=:cuno Parameters: disc=66 cuno=000974 Update CustomersPriceGroups set 1ZA00=:disc Where cuno=:cuno Parameters: disc=60 cuno=000974 What does this mean ? Here is the code fragment c:

How to find the column used in the dynamic query without executing whole query

微笑、不失礼 提交于 2019-12-21 06:48:33
问题 Problem Statement I have a dynamic SQL which i need to store in a table ,but before storing the sql i need to validate the sql with the list of columns stored in another table. Without executing the query , is it possible to find name of columns in the select ? Approach1 Only option i can think of is ,try to use explain plan of the query and read the meta data in the data dictionaries table .But unfortunately i am not able to find any table with such data.Please let me know if you know such

How to design a generic database whose layout may change over time?

拜拜、爱过 提交于 2019-12-20 20:42:28
问题 Here's a tricky one - how do I programatically create and interrogate a database whose contents I can't really foresee? I am implementing a generic input form system. The user can create PHP forms with a WYSIWYG layout and use them for any purpose he wishes. He can also query the input. So, we have three stages: a form is designed and generated. This is a one-off procedure, although the form can be edited later. This designs the database. someone or several people make use of the form - say

Is there a dynamic Sql builder library for .Net? [closed]

感情迁移 提交于 2019-12-20 10:29:59
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Something like this. http://code.google.com/p/squiggle-sql/wiki/Tutorial. This is required for cases where It is required to build complex sql from the user input from UI. Currently in the project I am working is using String Manipulation which looks ugly and is difficult to maintain. 回答1: Try DbExtensions,

Passing the table as a parameter

本秂侑毒 提交于 2019-12-20 06:47:38
问题 I have to convert from lat and long to geom to use PostGIS. My problem, I have various tables from different locations and I want to pass the table as a parameter to the function. I'm trying this: CREATE or REPLACE FUNCTION convert_from_lon_lat(float,float,character varying) RETURNS integer AS $$ select id from $3 as vertices order by vertices.geom <-> ST_SetSrid(ST_MakePoint($1,$2),4326) LIMIT 1; $$ LANGUAGE SQL; but I get a syntax error. EDIT1: So I changed the previous code to this: CREATE

Oracle SQL — Grabbing values from multiple rows

梦想的初衷 提交于 2019-12-20 04:55:11
问题 I have a table like this: TABLE: FACTS ID KEY VALUE 1 name Jeremy 1 height 5'11 1 awesomeness 10 2 name Mark 2 awesomeness 4 3 height 4'6 So, the (ID,KEY) tuple can be considered as a primary key. I am trying to return rows like this: ID NAME HEIGHT AWESOMENESS 1 Jeremy 5'11 10 2 Mark (null) 4 3 (null) 4'6 (null) So other than by doing a sub-select for each column, how can grab the key values, if they are there, and collect them into my single row? What I tried so far was: SELECT id, CASE

How to pass NEW.* to EXECUTE in trigger function

≡放荡痞女 提交于 2019-12-20 03:51:42
问题 I have a simple mission is inserting huge MD5 values into tables (partitioned table), and have created a trigger and also a trigger function to instead of INSERT operation. And in function I checked the first two characters of NEW.md5 to determine which table should be inserted. DECLARE tb text; BEGIN IF TG_OP = 'INSERT' THEN tb = 'samples_' || left(NEW.md5, 2); EXECUTE(format('INSERT INTO %s VALUES (%s);', tb, NEW.*)); <- WRONG END IF; RETURN NULL; END; The question is how to concat the NEW.

Update multiple columns that start with a specific string

我与影子孤独终老i 提交于 2019-12-20 03:33:08
问题 I am trying to update a bunch of columns in a DB for testing purposes of a feature. I have a table that is built with hibernate so all of the columns that are created for an embedded entity begin with the same name. I.e. contact_info_address_street1 , contact_info_address_street2 , etc. I am trying to figure out if there is a way to do something to the affect of: UPDATE table SET contact_info_address_* = null; If not, I know I can do it the long way, just looking for a way to help myself out