Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
| Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 5th, 2003, 01:52 AM
Registered User
 
Join Date: Jun 2003
Location: Mumbai, Maharashtra, India.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default query about data dispay in dbgrid.

Dear All user,
I am writing application which tracks your expenses. In that application the data structure is as follows. I am using credit as positive values & credit as negative values.

Date | Particulars | Money
------------------------------
1-1-03 | Salary | 8000
2-3-03 | Petrol | -500
3-5-03 | shares money | 1000
4-5-03 | Medicines | -200

Now my question is I want to show the data to the user as follows :

Date | Particulars | In | Out
-----------------------------------
1-1-03 | Salary | 8000|
2-3-03 | Petrol | | 500
3-5-03 | shares money | 1000|
4-5-03 | Medicines | | 200

I hope you all will understand my problem.

Pl. help me.

Regards,
Chandrakant


 
Old July 8th, 2003, 04:46 AM
Authorized User
 
Join Date: Jun 2003
Location: Goodlands, n/a, Mauritius.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to psychadelic
Default

Hello

try these queries to get the result you want. They work with SQL Server and Ms Access though, so modify them is you are using another RDBM.

SQL Server:
Code:
SELECT     Date, Particulars,
    (CASE 
        WHEN Money < 0 THEN 0 
        ELSE Money 
    END) AS [In],  
    (CASE      
        WHEN Money >= 0 THEN 0 
        ELSE Money 
    END) AS [Out]
FROM YourTableName
!! IN is a reserve word in SQL Server and must be enclosed in braces.

Ms Access:
Code:
SELECT Date, Particulars, 
    IIf([Money]>=0,[Money],0) AS [In], 
    IIf([Money]<0,[Money],0) AS Out
FROM YourTableName;
cheers,

psychadelic




Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Builder 6 - Getting a value from a DBGRid rowin C++ Programming 0 June 1st, 2006 10:55 AM
How to edit in dbgrid? d_saikrishnan Pro VB 6 0 May 12th, 2006 10:51 AM
How to edit in dbgrid? d_saikrishnan Beginning VB 6 0 May 12th, 2006 10:49 AM
C++ Builder 6 - DBGrid rowin C++ Programming 0 April 13th, 2006 06:39 AM
True DBGrid 8.0 KalluMama Pro VB 6 1 August 10th, 2004 01:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.