473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How to execute all rows in a dynamic query

1
Hi,

I want to create a Procedure in sql server.That will search data dynamically from different table and columns
Data is like in a Hierarchical form
('\Locations\F-Olympia Armory Complex (OL-01)\Olympia Armory Building (102660)')
So my paramter in the fuction are
table name
column name
level
( e.g. if i give value as 2 it will return "F-Olympia Armory Complex (OL-01)")
I am able to write this for one row ,but i want to enchance this for all rows


Create Procedure funct_Hierarchy(@p_table_name varchar(200),
@Col_name varchar(200),@level int)

As
Begin
DECLARE @v_str NVARCHAR(400)
Declare @v_col varchar(200)
DECLARE @i integer
DECLARE @pos integer
DECLARE @pos1 INTEGER
DECLARE @v_sql NVARCHAR(500)
Declare @P_sql_msg varchar(200)

Set @v_str=''
Set @v_sql=''

Set @v_sql=N'Select @v_col='+ @Col_name + ' From ' + @p_table_name + ' Where spec_id=3005993 '

Exec sp_EXECUTEsql @v_sql , N'@v_col VARCHAR(200) out'
,@v_str OUT

IF @@ERROR <> 0
BEGIN
SET @P_sql_msg = -1
END

Set @pos1=0
WHILE (@i <= @level )
BEGIN
set @pos = patindex('%\%',@v_str)
SET @pos1 = @pos1 + @pos
set @v_str = SUBSTRING ( @v_str , @pos+1 , len(@v_str)-@pos )
SET @i = @i+1
END

set @pos = patindex('%\%',@v_str)
IF (@pos > 0)
BEGIN
SET @v_str = SUBSTRING ( @v_str ,1, @pos-1)
END

SET @P_sql_msg = @v_str
print @P_sql_msg

End
May 14 '07 #1
0 1221

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sheila King | last post by:
I have searched for an answer to this question on the comp.lang.python archives at Google Groups, and also looked through the (sparse) MySQLdb documentation, and cannot confirm for a FACT what I...
1
by: PJ | last post by:
<% Set Conn = Server.CreateObject("ADODB.Connection") Conn.open application("dtat_motor_connectionstring") set rs = new adodb.recordset 'Set RS = Conn.Execute(' "exec spcn_update_transactions &...
5
by: Gustavo Randich | last post by:
Hello, I'm writing an automatic SQL parser and translator from Informix to DB2. Now I'm faced with one of the most difficult things to translate, the "foreach execute procedure" functionality...
4
by: Laura | last post by:
Here's the situation: I'm trying to use an update query to copy data from one row to another. Here is the situation: I have 5 companies that are linked to each other. I need to show all 5...
7
by: JIM.H. | last post by:
Hello, Is there any difference to between SLQ string in the code and call execute query and call a stored procedure and execute the query that way concerning speed, effectiveness, reliability,...
2
by: Wei Wang | last post by:
Hi, I want to do a select in dynamic command, something like: TRIGGER FUNCTION DECLARE table_name_suffix text; temp_result RECORD; temp_result2 RECORD;
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
8
by: johnlichtenstein | last post by:
I am using cx_Oracle and MySQLdb to pull a lot of data from some tables and I find that the cursor.execute method uses a lot of memory that never gets garbage collected. Using fetchmany instead of...
5
by: alingsjtu | last post by:
Hello, every body. When execute dynamic generated multiple OPENQUERY statements (which linkes to DB2) in SQLServer, I always got SQL1040N The maximum number of applications is already connected...
7
by: ChaosKCW | last post by:
Hi I am trying to use pymssql, and have an issue where by the execute (not the fetch) is appearing to load all records into memory. if I execute con = pymssql.connect(...) cur =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.