Click here to Skip to main content
15,949,686 members
Home / Discussions / Database
   

Database

 
GeneralRe: sql dmo quest Pin
Johnny Go-Lightly20-Nov-03 14:34
sussJohnny Go-Lightly20-Nov-03 14:34 
QuestionHow does DataView.RowFilter works? Pin
Alexandru Savescu19-Nov-03 7:11
Alexandru Savescu19-Nov-03 7:11 
AnswerRe: How does DataView.RowFilter works? Pin
Husein23-Nov-03 2:51
Husein23-Nov-03 2:51 
GeneralSelect reads from XML file in ado.net Pin
imran_shahid@msn.com18-Nov-03 21:24
imran_shahid@msn.com18-Nov-03 21:24 
Questionhow to apply filter to Master/Detail records in dataset Pin
imran_shahid@msn.com18-Nov-03 21:19
imran_shahid@msn.com18-Nov-03 21:19 
AnswerRe: how to apply filter to Master/Detail records in dataset Pin
gokselm22-Nov-03 14:31
gokselm22-Nov-03 14:31 
GeneralCursor Pin
Anonymous18-Nov-03 4:42
Anonymous18-Nov-03 4:42 
GeneralRe: Cursor Pin
Jeff Varszegi18-Nov-03 5:34
professionalJeff Varszegi18-Nov-03 5:34 
Try something like this instead of a cursor:

SQL
SELECT
    CASE a.TType
        WHEN 'E' THEN b.field1
        ELSE c.field1
    END as field1,
    CASE a.TType 
        WHEN 'E' THEN b.field2
        ELSE c.field2
    END as field2,
    CASE a.TType
        WHEN 'E' THEN b.field3
        ELSE c.field3
    END as field3 -- etc. etc.
FROM table1 a
LEFT JOIN table2 b ON a.SID=b.SID AND a.TranID=b.TranID
LEFT JOIN table3 c ON a.SID=c.SID AND a.TranID=c.TranID
WHERE
    a.DateEntered = (
        SELECT MAX(a1.DateEntered) FROM table1 a1 WHERE a.sid=a1.sid
    )


Here's another way, making use of a UNION:

SQL
SELECT * FROM (
    SELECT b.*
    FROM table1 a
    LEFT JOIN table2 b ON a.SID=b.SID AND a.TranID=b.TranID
    WHERE
        a.TType='E'
        AND
        a.DateEntered = (
            SELECT MAX(a1.DateEntered) FROM table1 a1 WHERE a.sid=a1.sid
        )

    UNION

    SELECT b.*
    FROM table1 a
    LEFT JOIN table3 b ON a.SID=b.SID AND a.TranID=b.TranID
    WHERE
        a.TType <> 'E'
        AND
        a.DateEntered = (
            SELECT MAX(a1.DateEntered) FROM table1 a1 WHERE a.sid=a1.sid
        )
) targetTable
ORDER BY 
    targetTable.field1 ASC -- or whatever


In general, I use cursors only as a very last resort.

I broke my rule this one time; I usually don't answer anonymous questions. Why don't you get an account? That way, you can receive an email when someone answers a question.


Regards,

Jeff Varszegi
Generalcall ado nextrecordset failed Pin
zhangxinghai17-Nov-03 21:52
zhangxinghai17-Nov-03 21:52 
Questionhow to store xml data from xml file in database table Pin
Kris{PL}17-Nov-03 11:55
Kris{PL}17-Nov-03 11:55 
GeneralBorland C++ Builder DB usage Pin
EricCartman17-Nov-03 5:43
EricCartman17-Nov-03 5:43 
GeneralSQLObjectListPtr Pin
ranjjj17-Nov-03 3:14
ranjjj17-Nov-03 3:14 
GeneralSQLObjectListPtr Pin
ranjjj17-Nov-03 3:14
ranjjj17-Nov-03 3:14 
Generalsqldmo.tlh Pin
ranjjj16-Nov-03 22:33
ranjjj16-Nov-03 22:33 
Generallistdatabasepermissions Pin
ranjjj15-Nov-03 23:53
ranjjj15-Nov-03 23:53 
GeneralLoad a file into a binary column in SQL server Pin
CillyMe15-Nov-03 17:32
CillyMe15-Nov-03 17:32 
GeneralRe: Load a file into a binary column in SQL server Pin
mhmoud rawas15-Nov-03 18:39
mhmoud rawas15-Nov-03 18:39 
GeneralRe: Load a file into a binary column in SQL server Pin
CillyMe16-Nov-03 22:32
CillyMe16-Nov-03 22:32 
GeneralLoad a file into a binary column in SQL server Pin
CillyMe15-Nov-03 17:31
CillyMe15-Nov-03 17:31 
GeneralRe: Load a file into a binary column in SQL server Pin
Jeff Varszegi18-Nov-03 5:38
professionalJeff Varszegi18-Nov-03 5:38 
GeneralSQL Server Date Problem Pin
sim_san15-Nov-03 1:16
sim_san15-Nov-03 1:16 
GeneralRe: SQL Server Date Problem Pin
Mike Dimmick15-Nov-03 1:55
Mike Dimmick15-Nov-03 1:55 
GeneralRe: SQL Server Date Problem Pin
sim_san17-Nov-03 6:40
sim_san17-Nov-03 6:40 
GeneralRe: SQL Server Date Problem Pin
Mike Dimmick17-Nov-03 6:54
Mike Dimmick17-Nov-03 6:54 
GeneralRe: SQL Server Date Problem Pin
sim_san22-Nov-03 6:23
sim_san22-Nov-03 6:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.