Showing posts with label sample. Show all posts
Showing posts with label sample. Show all posts

Monday, March 26, 2012

how to get the primary keys and display it horizontally?

sample results: <MRNID=10002><VesselCode=VSL1>

wherein MRNID and VesselCode are primary keys of the table.

What do you mean by "horozontally"

<MRNID=10002><VesselCode=VSL1>

This is horozontally.

<MRNID=10002>
<VesselCode=VSL1>

Would be vertical. Can you be a bit more clear?

|||

do you mean pivoting the table

well sql 2k5 has a pivot keyword

Wednesday, March 21, 2012

How to get the database file into .bak file format using C#

Hi,

I want to retrive the values from the database 'northwind' and then i want to store the backup files in"D:/Sample/north_database.bak" format(local machine).

I retrive the database values in .txt,XML format. Now i want to take in .bak format.

give the Suitable solution for this.

Subashini.G

subashi

Check out this article and then download the zip file, to see a sample of the code you want

http://www.codersource.net/csharp_sqldmo_sqlserver.aspx

HTH

|||

Hi,

They Above Article is useful for me. But this coding isstored is database Queries in text(txt) format but i need thedatabase table values stored in .bak format.

Give the solution please

|||

subashini

Take 2

Try

http://www.csharphelp.com/archives2/archive345.html

I think this gets you what you need.

HTH

|||

Thank you Very Much. This coding is very useful for me.....Smile

Regards

Subashini

How to get the count difference between two tables

Hi,
I need to calcualte the count difference between two tables. I will
apply the method to 6 count comparisons. The following is my sample
code, which did not work. Could anyone help me out? Thanks!
create table one
(x float)
insert into one
values(1)
insert into one
values(2)
create table two
(x float)
insert into two
values(1)
insert into two
values(2)
insert into two
values(3)
declare @.one int, @.two int, @.diff int
set nocount on
select count(*) from one
set @.one=@.@.rowcount
select count(*) from two
set @.two=@.@.rowcount
set @.diff=(@.two-@.one)
print @.diff
Thanks a lot!
MikeMichael -
Do this instead:
declare @.one int, @.two int, @.diff int
set nocount on
select @.one=count(*) from one
select @.two=count(*) from two
set @.diff=(@.two-@.one)
print @.diff
@.@.rowcount returns the number of rows returned by a query. So "Select
count(*) from any_table_here" will always have an @.@.rowcount = 1, because
there is only 1 value returned from a "Select count(*)" query.|||On Feb 8, 2:20 pm, apf <a...@.discussions.microsoft.com> wrote:
> Michael -
> Do this instead:
> declare @.one int, @.two int, @.diff int
> set nocount on
> select @.one=count(*) from one
> select @.two=count(*) from two
> set @.diff=(@.two-@.one)
> print @.diff
> @.@.rowcount returns the number of rows returned by a query. So "Select
> count(*) from any_table_here" will always have an @.@.rowcount = 1, because
> there is only 1 value returned from a "Select count(*)" query.
Hi,
Thanks for your help! It works perfect. Could you tell me when the
output goes to GRID or when the output goes to MESSAGE? Because I used
PRINT statement, the output goes to different places in different
runs.
Thanks,
Mike|||I'm not completely sure what you're asking.
When you use Query Analyzer, there is a drop down in the top navigation that
lets you choose whether the results are returned in a grid, in text, or
output to a file.sql

How to get System.Query Namespace

Hi all,

I tried to do the Linq sample program, Already i have added System.Query namespace. But I am getting some error

like No reference to System.Query.


In my system , i have installed VS 2005 and .Net Framework 3.0.

Apart from the this, please tell me , whether any software are required

Regards and Thanks

Thirumurugan


Using/import statements can only reach the assemblies that are known to the application. In some cases you must explicitly add a reference to an assembly to be able to use it. To use System.Query you need to add a reference to that assembly. Right click on the solution and choose references. Click add and System.Query.dll should appear in that list.

|||

I tried same what you mentioned but still i did not get System.Query reference.

|||

What do you mean? Did it not appear in the .NET tab when you click on add reference? Then it is probably not registered correctly in the GAC... Do you see any other 3.0 assemblies in the list?

sql

Monday, March 12, 2012

How to get results from a storedprocedure

To all,
I looked at the MS-SQL pubs sample database and execute the examplestored procedure reptq2 and I got 17 results set back. Where can I findan example using Visual Studio DataGrid or any means to get all theseresults from this SP.
Thanks,

Frank
Try this link for a two part tutorial in C# that can return 100 rows. Hope this helps.
http://www.dotnetjunkies.com/Tutorial/EA868776-D71E-448A-BC23-B64B871F967F.dcik|||I just remembered that Stored proc in Pubs used COMPUTE which is a none relational aggregate function in SQL Server so you have to make the code in the link work with the stored proc and Pubs. Hope this helps.|||Here's the same data from that stored procedure, in a single result set... Avoid COMPUTE BY.

use pubs
go

select
t.type,
t.pub_id,
t.title_id,
ta.au_ord,
Name = substring (a.au_lname, 1,15),
t.ytd_sales,
avg_pub.salessum as avg_pub,
avg_pub_type.salessum as avg_pub_type
from titles t
join titleauthor ta on t.title_id = ta.title_id
join authors a on a.au_id = ta.au_id
join
(
select
t.pub_id,
avg(t.ytd_sales)
from titles t
join titleauthor ta on t.title_id = ta.title_id
where
t.pub_id is NOT NULL
group by
t.pub_id
) avg_pub (pub_id, salessum) on avg_pub.pub_id = t.pub_id
join
(
select
t.pub_id,
t.type,
avg(t.ytd_sales)
from titles t
join titleauthor ta on t.title_id = ta.title_id
where
t.pub_id is NOT NULL
group by
t.pub_id,
t.type
) avg_pub_type (pub_id, type, salessum) on avg_pub_type.pub_id = t.pub_id and avg_pub_type.type = t.type
where
t.pub_id is NOT NULL
order by
t.type,
t.pub_id