SubQuery

  • Hi,

    When i run the follwoing query

    select * from dbo.Part_Mast

    where Part_Num in (select convert(varchar,convert(datetime,Date_Lst_Iss),103), Part_Num from dbo.Part_Mast where Part_Num LIKE (RTRIM('258095GB') + '%'))

    order by Part_Num

    i get the follwoing error

    Server: Msg 116, Level 16, State 1, Line 1

    Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

    Can anyone help?

    Thanx

     

  • Hi!!!

    In ur subquery that getting two columns as output which compar with one column from outer query......

    by removing convert(varchar,convert(datetime,Date_Lst_Iss),103) u will get output...

    select * from dbo.Part_Mast

    where Part_Num in (select Part_Num from dbo.Part_Mast where Part_Num LIKE (RTRIM('258095GB') + '%'))

    order by Part_Num

     

     

     


    Regards,

    Papillon

  • Hi,

    But I need that query, thats the query im trying to add to the orginal sql query. I'm trying to make it work with that query.

    any suggestions

    Thanx

  • Hi!!!!

    U can do....

    select * into #temp from (select Part_Num from dbo.Part_Mast where Part_Num LIKE (RTRIM('258095GB') + '%')) p

    and now u can use....

    select * from dbo.Part_Mast

    where Part_Num in (select Part_Num from #temp)

    order by Part_Num

    Drop table #temp

    ...


    Regards,

    Papillon

  • yes but what about the date?

  • Hi!!!

    Actually that was my mistake u should write this way.....

    select * into #temp from (select convert(varchar,convert(datetime,Date_Lst_Iss),103),Part_Num from dbo.Part_Mast where Part_Num LIKE (RTRIM('258095GB') + '%')) p

     

     


    Regards,

    Papillon

  • select * into #temp from

    (select convert(varchar,convert(datetime,Date_Lst_Iss),103), Part_Num from dbo.Part_Mast

    where Part_Num LIKE (RTRIM('258095GB') + '%'))

    select * from dbo.Part_Mast

    where Part_Num in (select Part_Num from #temp)

    order by Part_Num

    drop table #temp

    I get a syntax error

  • Hi!!!!!

    as seen ur post ur not alias subquery here..

    select * into #temp from (select convert(varchar,convert(datetime,Date_Lst_Iss),103),Part_Num from dbo.Part_Mast where Part_Num LIKE (RTRIM('258095GB') + '%')) P

    and then run this ......

    select * from dbo.Part_Mast

    where Part_Num in (select Part_Num from #temp)

    order by Part_Num

    Drop table #temp

    Hope that will clear u.........


    Regards,

    Papillon

  • even when  I run the first query first i get a bracket error where as they are no extra brackets also im running both the queries in a stored proceudre so i will be running them together.

  • hi!!!!

    Can u give me which query u run ...and what error msg u got there......


    Regards,

    Papillon

  • select * into #temp from

    (select convert(varchar,convert(datetime,Date_Lst_Iss),103), Part_Num from dbo.Part_Mast

    where Part_Num LIKE (RTRIM('258095GB') + '%'))

     

    Server: Msg 170, Level 15, State 1, Line 3

    Line 3: Incorrect syntax near ')'.

  • select P.* into #temp from

    (select convert(varchar,convert(datetime,Date_Lst_Iss),103), Part_Num from dbo.Part_Mast

    where Part_Num LIKE (RTRIM('258095GB') + '%')) P

  • SELECT *

    INTO #temp

    FROM( SELECT CONVERT( varchar, CONVERT( datetime, Date_Lst_Iss, 103)), Part_Num

               FROM dbo.Part_Mast

               WHERE Part_Num LIKE( RTRIM( '258095GB') + '%'))

    I wasn't born stupid - I had to study.

  • Whoa..

    ..what was the question again? I mean, do you need all this temptable juggling in the first place?

    Could the original poster perhaps state the real problem - that is what is your intentions? Please also provide some simple example that shows what your data and tables look like. Then - when we have agreed upon what to solve, we can think of something

    /Kenneth

  • Am I missing something ?

    Doesn't this SQL do the job ?

    select *

    , convert(varchar,convert(datetime,Date_Lst_Iss),103)

    from dbo.Part_Mast

    where Part_Num LIKE '258095GB%'

    order by Part_Num

    SQL = Scarcely Qualifies as a Language

Viewing 15 posts - 1 through 15 (of 24 total)

You must be logged in to reply to this topic. Login to reply