Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two SQL tables in the SQL database, I have 5 to 6 columns in the table. In the second column, i have a big Sentence with Words and Numbers.

I want a source code, in any programming language, to develop such that, from that entire sentence, i have to take a number, and i have to match that number with the data in the first column of other table.

If the number gets matched with any of the number in the second table, then it should print that entire row as output.

The 2nd table contains 3 columns, first column is with this number and the second two columns also contains numbers.
Posted
Comments
[no name] 25-Feb-15 0:36am    
Are you dealing with the database only or do you already have some application that can access the database?

How is the data inserted into the tables initially?
Krishna Chaitanya Bezawada 25-Feb-15 1:12am    
I am using Microsoft Sql server 2008 in my system.

I am using SQL management studio to insert data into the table.
[no name] 25-Feb-15 1:17am    
I was asking because if you already had some application that inserts the data or at least can read and modify it, you could create another (numerical) column for the table that has the "sentence-column" and extract and insert that number from the sentence in the application code (and then execute the join in a simple manner). If you're dealing with SQL Management Studio only you should investigate the options that Mika Wendelius presented to you below.
Suvendu Shekhar Giri 25-Feb-15 0:40am    
Some examples would help providing a better suggestion/solution.
Krishna Chaitanya Bezawada 25-Feb-15 1:17am    
1st table contain a statement like "There is a fluid loss of 10 m3/hr at 200 Kilometers". in one row

That 200 is present in a row in another table like below

Location Longitude Latitude
198 70.01564 78.0454
200 70.15121 78.1550

whenever we run the program it should take that 200 number from first table and try to find match with 2nd table. if match finds then, it should print that entire row. if match is not found, it should print nearest value's entire row.

Sounds like a problem that cannot be solved using pure SQL. Because of this I'd suggest using a stored procedure which would fetch the data, split the data in the column and try to find matching rows. In case of a match, the row would be added to a table variable and content of this table variable would be returned in the end.

Have a look at:
- CREATE PROCEDURE[^]
- SQL User Defined Function to Parse a Delimited String[^]
- DECLARE[^] for table variable
 
Share this answer
 
if your number got a fixed length then split the word to an array by space and tryparse it as number, if it is number, search using startwith/like command.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900