Help On create Store Procedure
I need to Create a Store Procedure under a different from the once I am connected.
Thanks
If you have the DB rights to do it, use
create procedure owner.proc_name as ...
Similar Messages
-
Create Store Procedure to Count Number of records in Database for each table
Hello,
I have created the code which counts the number of records for each table in database. However, I want create store procedure for this code this code that when ever use execute the Store Procedure can provide the database name to execute it and as a result
table will display number of records in each table.
Below you will find the code its working:
CREATE
TABLE #TEMPCOUNT
(TABLENAME
NVARCHAR(128),
RECORD_COUNT BIGINT)
-- Creating a TEMP table
EXEC
sp_msforeachtable
'insert #tempcount select ''?'', count(*) from ? with (nolock)'
SELECT
* FROM
#TEMPCOUNT
ORDER
BY TABLENAME
DROP
TABLE #TEMPCOUNT
This code need to be convert in store procedure and user can give database name when execute the procedure in order to count the records.
Looking forward for your support.
Thanks.
SharePoint_Consultant_EMEASomething like:
set quoted_identifier off
go
create procedure usp_TableCounts
@DBName as varchar(1000)
as
set nocount on
declare @SQLToExecute varchar(1000)
CREATE TABLE #TEMPCOUNT (TABLENAME NVARCHAR(128), RECORD_COUNT BIGINT) -- Creating a TEMP table
set @SQLToExecute = @DBName + ".dbo.sp_msforeachtable 'insert into #tempcount select ''?'', count(*) from ? with (nolock)'"
print @SQLToExecute
exec (@SQLToExecute)
SELECT * FROM #TEMPCOUNT
ORDER BY TABLENAME
DROP TABLE #TEMPCOUNT
GO
Satish Kartan www.sqlfood.com -
BODS cannot create store procedure at DB2 at Unix
Hi,
I run BODS X3.1 and it can't create, drop store procedures at DB2 at unix. It recommends to authorize the user to do so. However, I have checked DB2 online doc, it mentioned need to set CREATE PROCEDURE authority. However, I can't find any command to do it.
Does anyone using DB2 that can provide help?
Thank you.I think I got found the bug. It is select from a regular table to load another regular table using Auto correct load method. If only normal loading, no create procedure sql is generated and no warning message.
For using Auto correct load method:
(1) first, it got to perform drop procedure as:
DROP PROCEDURE "BODSOWN".di1125368_1FOOTE; .
Note:
(a) I run this command at db2 and it contain syntax error, saying:
SQL0104N An unexpected token ";" was found following "WN".di1125368_1FOOTE".
(b) which mean the semicolon ; is not needed. If I delete this ; away, it can go through but still will complain the stored procedure "BODSOWN.di1125368_1FOOTE" doesn't exist. But that is another issue which is expected.
(2) secondly, It will generate a CREATE PROCEDURE as such:
CREATE PROCEDURE
"BODSOWN".di1125368_1FOOTE ( IN before_c1 VARCHAR (100) , IN after_c1 VARCHAR (1) , IN after_c2 VARCHAR (40) , IN after_c3
INTEGER , IN after_c4 VARCHAR (100) )
LANGUAGE SQL
BEGIN
DECLARE local_var INT DEFAULT 0;
SELECT COUNT(*) INTO local_var
FROM "BODSOWN"."FOOTER_RECORD"
WHERE "DI_FILENAME" = before_c1 ;
IF local_var = 0 THEN
INSERT INTO "BODSOWN"."FOOTER_RECORD" ("RECORD_TYPE", "SRCSYS_OR_COUNTER", "ROW_COUNTER", "DI_FILENAME")
VALUES (after_c1, after_c2, after_c3, after_c4 );
ELSE
UPDATE "BODSOWN"."FOOTER_RECORD"
SET "RECORD_TYPE" = after_c1 ,
"SRCSYS_OR_COUNTER" = after_c2 ,
"ROW_COUNTER" = after_c3 ,
WHERE "DI_FILENAME" = before_c1 ;
END IF;
END
Note:
(a) this create procedure contains syntax error, the line "ROW_COUNTER" = after_c3 , a comma shouldn't be inserted which afterward is the WHERE clause. Meaning is should be "ROW_COUNTER" = after_c3 without comma.
(b) if i run this create procedure at db2 without the comma error, it will be successful, if not if will give error saying:
SQL0104N An unexpected token ""DI_FILENAME"" was found following "" =
after_c3 , WHERE". -
Plz help me create a Procedure with create view cmd
i want to create a view from the procedure like the following one,
It creates the proc but while running it show invalid column name please help me;
create or replace procedure asho2005.mock_pro( fin_fr_dt in date, fin_to_dt in date) is
ffdt date;
ftdt date;
begin
select to_date(fin_fr_dt,'dd-mm-yyyy') into ffdt from dual;
select to_date(fin_to_dt,'dd-mm-yyyy') into ftdt from dual;
execute immediate 'create or replace view mock_vu as select a.amt from cbtran a where chq_dt > ffdt and chq_dt <ftdt';
end;i want to create a view from the procedure like the
following one,
It creates the proc but while running it show invalid
column name please help me;
create or replace procedure asho2005.mock_pro(
fin_fr_dt in date, fin_to_dt in date) is
ffdt date;
ftdt date;
begin
select to_date(fin_fr_dt,'dd-mm-yyyy') into ffdt
t from dual;
select to_date(fin_to_dt,'dd-mm-yyyy') into ftdt
t from dual;
execute immediate 'create or replace view mock_vu
vu as select a.amt from cbtran a where chq_dt > ffdt
and chq_dt <ftdt';
end;Hallo,
your problem is , that execute immediate does't recognize ffdt
You have to concatenate literals
create or replace procedure asho2005.mock_pro( fin_fr_dt in date, fin_to_dt in date) is
ffdt date;
ftdt date;
begin
select to_date(fin_fr_dt,'dd-mm-yyyy') into ffdt from dual;
select to_date(fin_to_dt,'dd-mm-yyyy') into ftdt from dual;
execute immediate 'create or replace view mock_vu as select a.amt from cbtran a where chq_dt > '''||ffdt||''' and chq_dt <'''||ftd||'''';
end; BTW, your view doesn't return any rows
ffdt and < ffdt :-)
Besides that , it's a very very bad method!
You must not create views in runtime. Use of literals results in hard parsing .
The performance will be poor.
You have to create view in design time, and then simply use select:
select * from mock_vu where chq_dt > (your_date) and something else
HTH
Regards
Dmytro
corrected wrong number of quotes (no wonder ) :-)
Message was edited by:
Dmytro Dekhtyaryuk -
How to create store procedure using cursor, and looping condition with exce
Hi,
I am new in pl/sql development , please help me for follwoing
1. I have select query by joining few tables which returns lets say 100 records.
2. I want to insert records into another table(lets say table name is tbl_sale).
3. If first record is inserted into tbl_sale,and for next record if value is same as first then update into tbl_sale else
insert new row
4. I want to achieve this using store procedure.
Please help me how to do looping,how to use cursor and all other necessary thing to achieve this.DECLARE
b NUMBER;
BEGIN
UPDATE tbl_sale
SET a = b
WHERE a = 1;
IF SQL%ROWCOUNT = 0
THEN
INSERT INTO tbl_sale
(a
VALUES (b
END IF;
END;note : handle exceptions where ever needed
Regards,
friend
Edited by: most wanted!!!! on Mar 18, 2013 12:06 AM -
A little help for creating a procedure
Hi,
I'm new to oracle so i would really appreciate your help. Here is the scenario: i have several table in a database, in one table, let's call it table_a i have some values like: assignment, employee_id, account and so on. In another table, table_b i also have some data the is found in table_a like: employee_id, assignmnet, employee_name... and so on. I must create a procedure to check in table_a by value assignment(pk) and find what assignments are not in table_b and then insert these values in table_b, table_c.... . How do i create the comparison part?Hi,
If It would have to insert only in table_b, then you can go for MERGE, that will be fine instead of procedure.
Other options would be
INSERT ALL
INTO table_b VALUES (<required columns>)
INTO table_c VALUES (<required columns>)
SELECT <the columns>
FROM table_a
where assignmnet_id not in (select assignmnet From table_b);
- Pavan Kumar N -
In this practice, create a procedure to monitor whether employees have exceeded their average salary limits.
a. Add a column to the EMPLOYEES table by executing the following command:
ALTER TABLE employees
ADD (sal_limit_indicate VARCHAR2(3) DEFAULT 'NO'
CONSTRAINT emp_sallimit_ck CHECK (sal_limit_indicate IN ('YES', 'NO')));
a. Write a stored procedure called CHECK_AVG_SAL. This checks each employee's average salary limit from the JOBS table against the salary that this employee has in the EMPLOYEES table and updates the SAL_LIMIT_INDICATE column in the EMPLOYEES table when this employee has exceeded his or her average salary limit.
Create a cursor to hold employee IDs, salaries, and their average salary limit – lock the rows with the FOR UPDATE NOWAIT clause in your cursor definition.
Find the average salary limit possible for an employee's job from the JOBS table. The average salary limit is defined as (max salary + min salary)/2 . Compare the average salary limit possible for each employee to exact salaries and if the salary is more than the average salary limit, set the employee’s SAL_LIMIT_INDICATE column to YES; otherwise, set it to NO.
Add exception handling to account for a record being locked. This is the only exception you will need to check. This exception is Oracle non-predefined -0054. So you will need to associate it using the PRAGMA EXCEPTION_INIT. Then you can handle it with a standard WHEN clause in the EXCEPTION area of your program.
It might look like this in your declaration area:
e_resource_busy EXCEPTION;
PRAGMA EXCEPTION_INIT(e_resource_busy, -54);
c. Execute the procedure, and then test the results.
EXECUTE check_avg_sal
Now test the rows lock exception by starting another session executing the procedure again. Remember to SET SERVEROUTPUT ON. In this example I used the RAISE_APPLICATION_ERROR procedure in my exception section– this is what the output will look like. But you could also have printed a nice message using DBMS_OUTPUT.PUT_LINE. Your choice.
EXECUTE check_avg_sal
BEGIN check_avg_sal; END;
ERROR at line 1:
ORA-20001: Record is busy, try later.
ORA-06512: at "TEACH.CHECK_AVG_SAL", line 29
ORA-06512: at line 1
Query the EMPLOYEES table to view your modifications, and then commit the changes.
select e.employee_id, e.job_id, j.min_salary, e.salary, j.max_salary, e.sal_limit_indicate
from employees e , jobs j
WHERE e.job_id = j.job_id
EMPLOYEE_ID JOB_ID MIN_SALARY SALARY MAX_SALARY SAL
100 AD_PRES 20000 24000 40000 NO
101 AD_VP 15000 17000 30000 NO
102 AD_VP 15000 17000 30000 NO
200 AD_ASST 3000 4400 6000 NO
108 FI_MGR 8200 12000 16000 NO
109 FI_ACCOUNT 4200 9000 9000 YES
110 FI_ACCOUNT 4200 8200 9000 YES
111 FI_ACCOUNT 4200 7700 9000 YES
112 FI_ACCOUNT 4200 7800 9000 YES
113 FI_ACCOUNT 4200 6900 9000 YES
205 AC_MGR 8200 12000 16000 NO
206 AC_ACCOUNT 4200 8300 9000 YES
145 SA_MAN 10000 14000 20000 NO
146 SA_MAN 10000 13500 20000 NO
Commit
Commit complete.The below is what I have.. it is not working.. I am not sure what is wrong.
set server output on
---to add sal_limit_indicate column to employees table
ALTER TABLE employees
ADD (sal_limit_indicate VARCHAR2(3) DEFAULT 'NO'
CONSTRAINT emp_sallimit_ck CHECK (sal_limit_indicate IN ('YES', 'NO')));
--query employees table to make sure the column is added
select * from employees
----query to check average salary
select e.JOB_ID, e.SALARY,e.sal_limit_indicate,((min_salary+max_salary)/2) as avg_sal
from employees e, jobs
where e.job_id = jobs.job_id
---procedure to use in main procedure
create or replace procedure update_indicator
(emp_id employees.employee_id% type,
emp_sallimit employee.sal_limit_indicate% type)
is
begin
update employees
set sal_limit_indicate ='yes'
end update_indicator;
---procedure to update sal-limit_indicate to yes if salary is greater than average salary
create or replace procedure CHECK_AVG_SAL is
cursor sal_cursor is
select e.employee_id, e.SALARY ,e.sal_limit_indicate,j.avg_sal
from employees e, (select ((min_salary+max_salary)/2) as avg_sal, job_id from jobs)j
where e.job_id = j.job_id
and salary >avg_sal;
begin
for sal_rec in sal_cursor
loop
update_indicator(sal_rec.employee_id,sal_limit_indicate);
end loop;
end;
end CHECK_AVG_SAL; -
How to create Store Procedure for export result select in .txt or .csv
Hello,
I'm using MSSQL Server.
How to export results query in .txt or .csv?
But
I can not use bcp or SQLCMD.1) linked server
insert into txtsrv...table1#txt(CustomerNumber,CustomerName,EntryDate)
select orderid, shipname, orderdate
from Northwind..orders
Set up the linked server
Connecting a directory of text files as a linked server is easy. Here’s how:
In Windows, create a new directory for the linked server.
For this article, that directory will be E:\txtsvr.
Add that directory as a linked server with sp_addlinkedserver:
EXEC sp_addlinkedserver txtsrv, 'Jet 4.0',
'Microsoft.Jet.OLEDB.4.0', 'e:\txtsrv', NULL, 'Text'
That’s all that’s required to add the linked server txtsrv
as a connection to the text files in E:\txtsvr, but there are
no tables in txtsvr yet. Also missing is a required file, schema.ini,
which must contain a description of each table’s format.
You can learn more about schema.ini from the Microsoft MSDN Library,
but for now, just use Notepad or your favorite text editor
to create the file e:\txtsrv\schema.ini as shown in Listing 1.
In addition, create an empty text file in e:\txtsrv named table1.txt.
The file e:\txtsrv\table1.txt is now an empty table in the linked server txtsrv.
We can see that if we list information about all the tables in txtserv with
the system stored procedure sp_tables_ex:
EXEC sp_addlinkedsrvlogin txtsrv, FALSE, Admin, NULL
EXEC sp_tables_ex txtsrv
Text files are tables
We can’t issue a CREATE TABLE statement against this linked server,
but we have created a table easily enough. We can, however,
run INSERT and SELECT queries, if we use the four-part naming
convention <server>…<table> (that’s three dots):
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Help me create a procedure to rename plenty of constraints
about 500 tables' constraints require to be renamed from SYS**** to the table's name.
what procedure could you guys think of?
If you've used a previous one please let me know, or if you know where I could download a package, procedure or something, show me the link to get it.
My DB is: version 8173This Procedure renames PK to PK+TableName(excuse the german comments):
procedure rename_primary_key
is
cursor c_user_cons is
select
c.constraint_name,
c.constraint_type,
c.r_constraint_name,
rc.table_name r_table_name,
c.table_name,
to_char(NULL) key_columns,
i.tablespace_name
from user_constraints c, user_constraints rc, user_indexes i
where c.constraint_type in ('P','R')
and (c.r_constraint_name like 'SYS%' or c.r_constraint_name is null)
and c.constraint_name = i.index_name (+)
and c.r_constraint_name = rc.constraint_name (+)
order by c.constraint_type desc, c.table_name, c.constraint_name;
type cons_list is table of c_user_cons%rowtype;
key_columns varchar2(1000);
constraint_liste cons_list := cons_list(NULL);
begin
for rec in c_user_cons loop
-- Liste mit vorhandenen constraints erstellen
constraint_liste(constraint_liste.last) := rec;
for rec_col in (
select column_name, position
from user_cons_columns
where constraint_name = rec.constraint_name
order by position
) loop
if rec_col.position = 1 then
key_columns := rec_col.column_name;
else
key_columns := key_columns||','||rec_col.column_name;
end if;
end loop;
constraint_liste(constraint_liste.last).key_columns := key_columns;
constraint_liste.extend;
end loop;
constraint_liste.trim;
for i in constraint_liste.first..constraint_liste.last loop
-- Aufgrund der Sortierung des Cursors sind Foreign Keys zuerst in der Liste und
-- werden vor zugehörigem PK gelöscht
if constraint_liste(i).constraint_type = 'P' then -- PK löschen und neu anlegen
if constraint_liste(i).tablespace_name is not NULL then
-- nur ausführen, wenn eigener Index für PK vorhanden
execute immediate 'alter table '||constraint_liste(i).table_name||' drop primary key';
execute immediate 'alter table '||constraint_liste(i).table_name||' add (constraint PK'
||substr(constraint_liste(i).table_name, 1, 30)|| ' primary key ('
||constraint_liste(i).key_columns||') using index tablespace '
||constraint_liste(i).tablespace_name||')';
end if;
else -- FK löschen
execute immediate 'alter table '||constraint_liste(i).table_name||' drop constraint '||constraint_liste(i).constraint_name;
end if;
end loop;
for i in constraint_liste.first..constraint_liste.last loop
-- FK neu anlegen
if constraint_liste(i).constraint_type = 'R' then
execute immediate 'alter table '||constraint_liste(i).table_name||' add (constraint '
||constraint_liste(i).constraint_name||' foreign key('||constraint_liste(i).key_columns
||') references '||constraint_liste(i).r_table_name||' deferrable initially deferred)';
end if;
end loop;
end rename_primary_key; -
Hi all I face a error in create store procedure with like this code can u tel me what i did wrong .
here is my code
Create PROCEDURE [dbo].[FACT_CURRENT_VS_PRV]
@country nvarchar (50)
AS
BEGIN
if @command='XPO1'
BEGIN
WITH CurrentMonth(
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
as (
SELECT
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
FROM table 3
PreviousMonth(
SHORT_DESC,
PERIOD_CODE,
SPEC_CODE_IMS,
SPEC_CODE_PFZ,
Units,
[Values]
as (
SELECT
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
FROM table 4
SELECT * FROM CurrentMonth
except
END
If @country='XPO2'
BEGIN
WITH CurrentMonth(
SHORT_DESC,
PERIOD_CODE,
SPEC_CODE_IMS,
SPEC_CODE_PFZ,
Units,
[Values]
as (
SELECT
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
FROM table 1
PreviousMonth(
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
as (
SELECT
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
FROM table 2
SELECT * FROM CurrentMonth
except
select * FROM PreviousMonth
END
END
and i got this error
Msg 319, Level 15, State 1, Procedure FACT_CURRENT_VS_PRV, Line 116
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Msg 102, Level 15, State 1, Procedure FACT_CURRENT_VS_PRV, Line 152
Incorrect syntax near ','.
I m little bit confused why its happen
Thanks for helpThe error message is obvious. each CTE has to be preceded by ;
so use like this
Create PROCEDURE [dbo].[FACT_CURRENT_VS_PRV]
@country nvarchar (50)
AS
BEGIN
if @command='XPO1'
BEGIN
;WITH CurrentMonth(
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
as (
SELECT
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
FROM table 3
PreviousMonth(
SHORT_DESC,
PERIOD_CODE,
SPEC_CODE_IMS,
SPEC_CODE_PFZ,
Units,
[Values]
as (
SELECT
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
FROM table 4
SELECT * FROM CurrentMonth
except <you're missing something here>
END
If @country='XPO2'
BEGIN
;WITH CurrentMonth(
SHORT_DESC,
PERIOD_CODE,
SPEC_CODE_IMS,
SPEC_CODE_PFZ,
Units,
[Values]
as (
SELECT
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
FROM table 1
PreviousMonth(
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
as (
SELECT
SHORT_DESC ,
PERIOD_CODE,
SALES_VALUE_01 Units,
SALES_VALUE_02 [Values]
FROM table 2
SELECT * FROM CurrentMonth
except
select * FROM PreviousMonth
END
END
I think you're missing a statement after except in first condition
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
User define table and store procedure install
Hi there,
I like to deploy an addon, there are User define tables and store procedure need add to database, I wonder which chance is properly to add them, if add these user define objects in time of install, we can not get the enough information that connect to SQL server, and also create UDT need DIAPI. if put create UDT and UDsp in addon program, the problem is which DIAPI funciton or object can execute create store procedure SQL string.
Thanks for any help.
LanjunR. Schwachofer,
Thank you very much,
the way call isqlw.exe to run SQL script is a good way when install, but I confuse with two questions about this way. first, run isqlw.exe should provid loginid and password of SQL server, these two information need additional install dialog to get; second if use isqlw.exe the store procedure only create to the current company database, when create new compay DB the store procedure does not exist in new DB.
so I still do not know which way is the proper way to create SP for addon.
Thanks in advance.
Lanjun -
Insert and update same record of table using store procedure in oracle 10g
Hi,
I am using oracle sql developer for this.
I have created Store procedure which run after every 30mins of interval.
the problem is Ii need to insert data for first time of day then later that same record should update for particular field(here its plan code).
if new field is coming (if new plan code is generated) then it should insert data and again update same for interval.
means for each plan individual record(i.e. plan wise summary) should be there for only a day. next day new record for same plan.Hi,
You should use Merge like shown below:-
Merge into original_table a
using second_table b
on (a.primary_key=b.primary_key and a.primary_key........)
when match then
update set column_list=b.column_list
when not match then
isert into (column list)
values(a.column_list)If you dont know much about merge then follow below link..
http://www.oracle-developer.net/display.php?id=203
http://www.oracle-base.com/articles/10g/merge-enhancements-10g.php -
How to create a schema and assign roles with store procedure or function?
Hi All,
I am creating a webpage that will call oracle store procedure or function to create a schema and add roles. Please let me know if there a method to do that.
Thank youHi CristiBoboc,
Thank you very much for your help. Here is my code to create a user:
create or replace
FUNCTION user_create (user_name IN nvarchar2, user_pw IN nvarchar2)
RETURN number
IS
sql_stmt varchar2(200);
sql_stmt2 varchar2(200);
var_temp_count NUMBER(2);
un varchar2(30) := user_name;
up varchar2(30) := user_pw;
BEGIN
sql_stmt := 'create user :1 identified by :2
default tablespace users
temporary tablespace temp
quota 5m on users';
sql_stmt2 := 'grant developers to :1';
EXECUTE IMMEDIATE sql_stmt USING un,up;
EXECUTE IMMEDIATE sql_stmt2 USING un;
select count(*) into var_temp_count from dba_users where username = UPPER(user_name);
return var_temp_count;
END;
When I run, I get following error:
exec :myvar :=user_create('aaa','12345');
BEGIN :myvar :=user_create('aaa','12345'); END;
ERROR at line 1:
ORA-01935: missing user or role name
ORA-06512: at "CSDBA.USER_CREATE", line 15
ORA-06512: at line 1 -
Hello,
I want to create stored procedure which will give output rows from "values that are passed as one parameter (comma seperated) to store procedure".
Suppose ,
Parameter value : person 1,person2,person3
table structure :
Project Name | officers 1 | officers 2
here, officers 1 or officers 2 may contain names of multiple people.
expected OUTPUT : distinct list(rows) of projects where person 1 or person 2 or person 3 is either officer1 or officer 2.
please explain or provide solution in detail
- ThanksHi Visakh,
Thanks for reply.
But the solution you provided giving me right output only if officer 1 or officer 2 contains single value , not with comma seperated value.
Your solution is working fine for following scenario :
Project
Officers 1
Officers 2
p1
of11
off21
p2
of12
off22
with parameter : of11,off22 : it will give expected output
And its not working in case of :
Project
Officers 1
Officers 2
p1
of11,of12
off21,off23
p2
of12,of13
off22,off24
with parameter : of11,off22 : it will not give any row in output
I need patten matching not exact match :)
ok
if thats the case use this modified logic
CREATE PROC GetProjectDetails
@PersonList varchar(5000)
AS
SELECT p.*
FROM ProjectTable p
INNER JOIN dbo.ParseValues(@PersonList,',')f
ON ',' + p.[officers 1] + ',' LIKE '%,' + f.val + ',%'
OR ',' + p.[officers 2] + ',' LIKE '%,' + f.val + ',%'
GO
Keep in mind that what you've done is a wrong design approach
You should not be storing multiples values like this as comma separated list in a single column. Learn about normalization . This is in violation of 1st Normal Form
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Create directory issue in Store Procedure
Hi Guys,
can any one help?
I am using XP, Oracle 10g, sql developer and Sql Plus.
I am trying to create directory in storeprocedure, but it not let me to do that thing. below is the statement i am using
create or replace directory public_access as '/tmp/public_access';
please let me know hoe can i initialize my dir object in store procedure.
Thanksuser13012136 wrote:
Hi Guys,
can any one help?
I am using XP, Oracle 10g, sql developer and Sql Plus.
I am trying to create directory in storeprocedure, but it not let me to do that thing. below is the statement i am using
create or replace directory public_access as '/tmp/public_access';
please let me know hoe can i initialize my dir object in store procedure.
ThanksTypically best NOT to do something like this in a procedure, but there are cases where it's needed.
In those cases, you need to use Native Dynamic SQL.
execute immediate 'create or replace directory public_access as ''/tmp/public_access'''; Assuming your syntax was correct before (i just copied and pasted what you had, adding quotes where needed).
Maybe you are looking for
-
Hi Communitty. In my house we are going to update all out devices and computers. we share 1 apple id account with all members. Can we continue using Itunes Cards as a prefered payment? since we do not use CC for anything that has to do with purchase
-
My ipod nano (2nd gen) is not syncing to itunes.
Hope someone can help. I have an IPOD Nano (2nd Gen) and all of a sudden i can no longer get my IPOD to sync with Itunes. It has worked in the past but just recently the ipod icon does not show on the source pane, when i go in to devices all items ar
-
Multiple traffic lights in ALV
Hi friends, is it possible to have more than one traffic lights colomn in ALV OO ? i displayed the first one, but i need to display 3 traffic lights in 3 different colomns in my ALV (wich has 10 columns) Thanks in advance, Soufiane
-
When using Polycom PVX windows based IP video conferencing software the remote site can see and here me but I am unable to see and hear them. The VC working correctly with an older Netgear wireless router and if I bypass TC completly and connect dire
-
hi guys, I posted this question a week ago, I am resposting this again to ask some help. I am Installing XI on AIX 5.3 and Oracle 10g. Currently I am on phase 38 which is "Install Software units". A day passed by and still it hasn't moved to the next