SQL Help - Sajha Mobile
SAJHA MOBILE
SQL Help
Posts 4 · Viewed 3490 · Go to Last Post
stylish
· Snapshot
Like · Likedby · 0

Hi Frens,

Create table table1

(

col1 varchar(10)

)

Create table table2

(

col2 int

)

insert into table1 values('1,2,3,4')

insert into table2 values(1)

insert into table2 values(2)

insert into table2 values(3)

insert into table2 values(4)

insert into table2 values(5)

insert into table2 values(6)

insert into table2 values(7)

insert into table2 values(8)

insert into table2 values(9)

 

So table1 has 1,2,3,4

Table2 has 1 - 9 as rows

  I want to write a stament so that i get the result set like this 1- 4 as rows that means those values that is in the table1 but remember folks the datatype here is varchar.

WIll appreciate ur help

 

calciteko
· Snapshot
Like · Liked by · 0
Which database server is this like SQL server, Oracle, or MySQL....
Do you know what kind of language are you using like C#, PHP, ColdFusion ...
batuwa
· Snapshot
Like · Liked by · 0

give us lil more detail on this. What language u using and where are you trying to populating the table from. I mean, are you trying to populate data from another table into your table?

However, I am not sure if the following will work, but if you're on Oracle, this might be hint:

insert into table1(col1) (select  myvarchar( col) from (select '1'  as col from dual
                                                                                union
                                                                                select '2' as col from dual
                                                                                union
                                                                                select '3' as col from dual
                                                                                union
                                                                                select '4' as col from dual))

The last select statement, by default, lists values vertically as 4 different rows like:

1
2
3
4
 which has to be converted to 1,2,3,4 as single row in single column.

In this case, I used myvarchar() aggregate function, which I didn't give you detail. You need to define that function in your database. For the second part, you already got the hint.

If you're on SQL server, there might be easier way to do this. Let me know if this is what you're trying to do. I will give you more detail on that aggregate function.

stylish
· Snapshot
Like · Liked by · 0

Guys I am using SQL Server. I was creating a stored procs using T-SQL.

Plz help

 

Please log in to reply to this post

You can also log in using your Facebook
View in Desktop
What people are reading
You might like these other discussions...
· Posts 5 · Viewed 770 · Likes 3
· Posts 6 · Viewed 526
· Posts 2 · Viewed 563
· Posts 1 · Viewed 151
· Posts 1 · Viewed 167
· Posts 1 · Viewed 311
· Posts 6 · Viewed 1003 · Likes 2
· Posts 2 · Viewed 1011
· Posts 2 · Viewed 686
· Posts 1 · Viewed 360



Travel Partners
Travel House Nepal