473,395 Members | 1,885 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,395 software developers and data experts.

Regex in Stored Procedure Problem

296 100+
Whe I execute the below procedure by EXEC SearchAllTables '[0-9]{3}' no results are coming -->


Expand|Select|Wrap|Line Numbers
  1. drop proc SearchAllTables
  2. GO
  3.  
  4.  
  5. CREATE PROC SearchAllTables
  6. (
  7.     @SearchStr nvarchar(100)
  8. )
  9. AS
  10. BEGIN
  11.  
  12.     CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))
  13.  
  14.     SET NOCOUNT ON
  15.  
  16.     DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
  17.     SET  @TableName = ''
  18.     SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
  19.  
  20.     WHILE @TableName IS NOT NULL
  21.     BEGIN
  22.         SET @ColumnName = ''
  23.         SET @TableName = 
  24.         (
  25.             SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
  26.             FROM     INFORMATION_SCHEMA.TABLES
  27.             WHERE         TABLE_TYPE = 'BASE TABLE'
  28.                 AND    QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
  29.                 AND    OBJECTPROPERTY(
  30.                         OBJECT_ID(
  31.                             QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
  32.                              ), 'IsMSShipped'
  33.                                ) = 0
  34.         )
  35.  
  36.         WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
  37.         BEGIN
  38.             SET @ColumnName =
  39.             (
  40.                 SELECT MIN(QUOTENAME(COLUMN_NAME))
  41.                 FROM     INFORMATION_SCHEMA.COLUMNS
  42.                 WHERE         TABLE_SCHEMA    = PARSENAME(@TableName, 2)
  43.                     AND    TABLE_NAME    = PARSENAME(@TableName, 1)
  44.                     AND    DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
  45.                     AND    QUOTENAME(COLUMN_NAME) > @ColumnName
  46.             )
  47.  
  48.             IF @ColumnName IS NOT NULL
  49.             BEGIN
  50.                 INSERT INTO #Results
  51.                 EXEC
  52.                 (
  53.                     'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630) 
  54.                     FROM ' + @TableName + ' (NOLOCK) ' +
  55.                     ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
  56.                 )
  57.             END
  58.         END    
  59.     END
  60.  
  61.     SELECT ColumnName, ColumnValue FROM #Results
  62. END
May 3 '08 #1
1 2014
debasisdas
8,127 Expert 4TB
do you have matching data in the table for the query to filter ?
May 5 '08 #2

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

Similar topics

4
by: Michael Trosen | last post by:
Hi Everyone, I hope someone can help, I'm pretty new to pro*c programming. I have the following application setup: a pro*c program calls a stored procedure and recieves a cursor back: the...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
7
by: Jeff Wang | last post by:
Hi all, Can someone help me out? I've been struggling with this for almost a week and still have no clue what's wrong. Basically I want to write a DB2 stored procedure for OS/390 in REXX. In...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
6
by: Wojciech Wendrychowicz | last post by:
Hello to All, I'm trying to retrieve records from AS/400 in an VBA application. So, I've made an RPG program, then a stored procedure wchich calls that RPG program, and finally some VBA code to...
4
by: Chuck Haeberle | last post by:
I have an interesting regular expression challenge for someone more experienced with them than I for a data layer class... I need an expression to search a SQL statement (any type, SELECT INSERT...
2
by: Eli | last post by:
Hi all We currently have a strange problem with calling a Stored Procedure (SQL Database) in our C# Project. The only error I get is "System error" which says a lot :) Background: We have...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
4
by: nishi57 | last post by:
I hope I can get some help regarding this issue, which has been going on for a while. I have a desktop user who is having problem running "Stored Procedures". The DB2 Connect application works fine...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.