Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Wednesday, March 28, 2012

making two sums in one query

Hi

Im new in this forum so don't if this is the right place to post these kind of questions..

Im using vb2005 and have made a program that deals with customers and payments.

I have a table called acount. Roughly it contains these columns

Number, amount, type..

type can be a payment or a charge

I would like to have a query that gives me this result:

Number, sum(payments), sum(charges) (grouped by number)

I think it is some type of merging these to querys

select number, sum(amount) where type = 0 group by number

and

select number, sum(amount) where type <> 0 group by number

Im using it to calculate a customers acount to see if they have paid to much or to little.

Any ideas?

Something like this


select number,
sum(case when type=0 then amount else 0 end) as payments,
sum(case when type<>0 then amount else 0 end) as charges
from mytable
group by number

|||

i just tried that, but get some kind of error from vbs error handling.. Its danish so the number is called nr and acount called konto. this is what i typped:

select nr,sum(case when type=0 then amount else 0 end) as pay, sum(case when type<>0 then amount else 0 end) as charges from konto group by nr

Can it have something to do with that ive tried it on an access database?

The program should be able to use both access and sql server..

|||Access doesn't support CASE expression so you cannot use the same SELECT statement if you want to run against Access & SQL Server. You have to use IIF in Access instead of CASE. Otherwise, the rest of the SELECT statement syntax should be fine. Alternatively, you can create a view in SQL Server and Access that contains the database specific query and query the view from the client side.|||

?v..

I cant get the iif sentence to work either.. Is this the query?

select nr,sum(iif when type=0 then amount else 0 end) as pay, sum(iif when type<>0 then amount else 0 end) as charges from konto group by nr

Am i missing something in the query?

|||

Please check the Access documentation for syntax on how to use IIF. It should be:

select nr,sum(iif(type=0, amount, 0)) as pay, sum(iif(type<>0, amount, 0)) as charges from konto group by nr

Also, this newsgroup is for SQL Server questions so please post only TSQL related questions or unless you are using SQL Server in some form or another. You need to post Access questions in the Access newsgroups to get better response.

Monday, March 26, 2012

Making field read only

Goodday all

I have a details view on a vb form .

Now that i have been working on the program , i realise that i would like to make some fields " read only '

Is that possible , and if so how?

Thanks

Rob

You could:

1 - Set permissions in SQL Server for SELECT only.
2. -Set the form properties to 'Read Only' (Enabled = False) for that textbox.

sql

making changes to templates. Need help urgent

I created templates in the folder C:\Program Files\Microsoft SQL
Server\80\Tools\Report Designer\ProjectItems\ReportProject\. My question is
:Will any changes to the template automatically reflect changes to reports
that have already been created using this template.If that is possible how do
i do it.
I am unable to find answers to this issue. Appreciate if somebody can
provide a solution.Changes to a template will not reflect in reports created by that template as
they could be published anywhere.
"Kiran" wrote:
> I created templates in the folder C:\Program Files\Microsoft SQL
> Server\80\Tools\Report Designer\ProjectItems\ReportProject\. My question is
> :Will any changes to the template automatically reflect changes to reports
> that have already been created using this template.If that is possible how do
> i do it.
> I am unable to find answers to this issue. Appreciate if somebody can
> provide a solution.

Making backup from vb2005 program

Can i send a command from my vb2005 program to tell the database to make a backup? Or how is this else done...

You would 'ExecuteNonQuery', and the command.text (query) would be a 'fleshed' out version of the BACKUP DATABASE command.

For complete syntax, refer to Books Online, Topic: Backup Database

|||Another option would be to use the object model of SMO.

Jens K. Suessmeyer.

http://www.sqlserver2005.de

Friday, March 23, 2012

Making a Select between two diferent SQL Servers...Urgent please Help

Hi there friend...I'm in a midle of a program(vb.net). and i've got this problem, I've got do compare two tables from two diferent sql servers. Is this possible? How can I do this?

Please, this is really urgent.

Thank you for your attentionLook into Linked Servers in Books Online. Then you can reference another server once it's linked to your SQL Server. HTH|||Tnks, i will do that.