|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Query - General - Select query..(Quite urgent)..
Hi Friends,
in my application i need to do the following.. i have a one tbl(named as tbl1) and have the records like the following tbl1 id lotno qty type serialno 0 43243 8.0 test 123456 0 54236 8.7 result 123456 0 34535 8.8 return 123456 in the above table i have 3 type of record for the same serial no..so in that i need to insert into these 3 types records into one row at another table like the following.. tbl2 qty test(type of tbl1) result return 8.0 42243(lotno of tbl 1) 54236 34535 the above is output i need.. actully in this table(tbl2)all the coumns (based on tbl1 type)..so i need to select lotno on the first table(tbl1) based on the type and insert into one row like the above output table(tb2) and the qty is based type test. and in my first table(tbl1) , here i showed only one serialno , but actually i have many serialno like that.. each serial no have 3 type os records and some have 2 types of records what query will make this things.. i am using mysql datbase and really quite urgent.. waiting for your valuable reply.. with regards, krish |
|
#2
|
|||
|
|||
|
Hope you have your answer by now. Visit SQL website to learn SQL language. For starters, get data with a query something like:
"SELECT lotno FROM tbl1 WHERE type=" & textBoxType Then use UPDATE, INSERT commands to save data. This is very rough because could not really follow your narrative. |
|
#3
|
|||
|
|||
|
declare @t table(id int, lotno int,qty decimal(18,2), types varchar(32), serialno int)
insert into @t select 0, 43243, 8.0, 'test', 123456 insert into @t select 0, 54236, 8.7, 'result', 123456 insert into @t select 0, 34535, 8.8, 'return', 123456 select min(qty),max([test]),max([result]),max([return]) from @t pivot (max(lotno) for types in ([test],[result],[return]))p use dynamic crosstab too for sql2000 pivot will work in sql2005 only. check this link too http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx |
|
#4
|
|||
|
|||
|
Re:Select Query
Hi, I hope that the below SQL query will be useful for you
Select isnull(test.qty,0) as [Qty], isnull(test.lotno,0) as [Test],isnull(result.lotno,0) as [result] ,isnull([return].lotno,0) as [Return] from (select id,qty,lotno from test2 where type = 'test')test right outer join(select id, lotno from test2 where type = 'result')result on test.id = result.id right outer join(select id, lotno from test2 where type = 'return') [return] on test.id = [return].id or result.id = [return].id Note: test2 is a table name Thanks & Regards Sakthimeenakshi.S |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Query - General - Select query..(Quite urgent).. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|