April 7, 2008 at 9:00 am
need to search for a string
for ex. tablename_ref.hello
i need to find hello from columns in a table and also i have some columns like
tablename.hello1 in same table 'tblObj'
i need to bring hello ,hello1 into two temp tables............
April 7, 2008 at 11:32 am
Are you looking for column names or the contents of the columns?
If column names, then sys.columns has all of those and you can select from that.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
April 7, 2008 at 11:35 am
i am looking for data inthe columns...........data means in the column which are attached to _ref.
April 7, 2008 at 11:39 am
select ColName
from dbo.TableName
where ColName like '%hello%'
That will give you the rows that contain the string "hello". Keep in mind that this will find any string, not just whole words. For whole words, your best bet is full text indexing.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
April 7, 2008 at 11:55 am
'hello' is not the specific name.............we have different data in place of that..............data is dynamic.............and also we have like
tblname _ref.data and
tblname.data1
we need to get data(-ref fields) and data1 into two temp tables after extraction
April 7, 2008 at 11:57 am
Use whatever string you're looking for, of course. Doesn't have to be "hello", can be anything at all.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
April 7, 2008 at 12:00 pm
'hello' is not the specific name.............we have different data in place of that..............data is dynamic.............and also we have like
tblname _ref.data and
tblname.data1
we need to get data(-ref fields) and data1 into two temp tables after extraction
the data/columns is dynamic.......what i think is we need to search for string next to _ref.
can u plz help me in that
April 7, 2008 at 12:31 pm
If I'm understanding you correctly, you'll need to use dynamic SQL for that.
You build the query as a variable, then execute it with sp_executeSQL.
For example:
declare @sql varchar(max), @Col varchar(128), @Table varchar(128),
@Search varchar(100)
select @Col = 'Name', @Table = 'Customers'
create #TempTable (
[TableName] varchar(128),
[ColName] varchar(128),
ID int)
select @sql = 'insert into #temptable([tablename],[colname],id)
select ''' + @table + ''',''' + @col + ''',id from dbo.' + @table + ' where '
+ @col + ' like %' + @search + '%'
exec master.dbo.sp_executesql @sql
Then you can set the table names, column names and search strings in code.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
April 7, 2008 at 12:48 pm
thanks...........
i need to search for data next to _ref
April 7, 2008 at 12:57 pm
Chinni -
GSquared has tried to answer your question 3 separate times, and you're essentially coming back with the same information each time. Although I'm sure he thoroughly enjoys guessing at what you're looking for, perhaps help him out a little
Try adding some more info, say - something specific, an example. What exactly is _ref supposed to represent? A table? a c# variable of some sort?
What would a typical search look like? what are you doing with the results? how is this to be called? from what kind of app?
You know - something to actually work with?
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
April 7, 2008 at 1:14 pm
where is this information stored? where are the name of the destination tables stored?
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
April 7, 2008 at 1:19 pm
we dont need the table name.........just need to display the attachments to it...........
all the table names are present in another table.................
April 9, 2008 at 8:10 am
"Attachments" to a table??
The problem is that you are using some sort of unique terminology that probably only exists in the company you work for. Unless you define these terms, I can't understand what you're asking for.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply