Showing posts with label tables. Show all posts
Showing posts with label tables. Show all posts

Thursday, March 29, 2012

extract information from tables

Hello Guys,

my collegue left the job and I have been chosen to work on his assignments.

He posted this question before and got the answer but I couldn't find a way to implement it in the program.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1726638&SiteID=1

I changed the database a bit as I couldn't understand his logic of putting both PayID and TransNo as this would be a linked table and should have many to many relationship

Code Snippet

TransactionID int Unchecked
TransNo varchar(50) Checked
RefNo nvarchar(50) Checked
FundCodeID smallint Checked
TransAmount decimal(18, 2) Checked
Description varchar(100) Checked
TransPayID (from TransPayLnk Table as foreign key)

Tbl_TransPayLnk

Code Snippet

TransPayID int Unchecked
TransNo varchar(50) Checked
TransDate datetime Checked
Operator char(5) Checked
TerminalID tinyint Checked
Flagged char(1) Unchecked
Remarks text Checked
RemarksDate datetime Checked
TPayment decimal(18, 2) Checked

Tbl_Payment

Code Snippet

PaymentID int Unchecked
PayType varchar(50) Checked
Amount decimal(18, 2) Checked
TransPayID (Foreign Key from Tbl_TransPayLnk)

My requirement would stay the same, I would need to put the data from these 3 tables into a single line without duplicating the records and I would need to display them in a DataGridView.

P.S: Would it be possible to have Mixed when a TransPayID is matched in Tbl_payment with more then one record rather then brining cash and cheque.

Thank you all for your help.

Bye


Gemma

The answer is already available on the given post itself. What exactly you are looking for?|||

Yes the answer is there but I changed the table structure and though I appreciate the effort of DaleJ but I can't seem to display it like this in a DataGridView Row.
Why don't you check the new table structure and please reply on this.

Thanks for your help

Gemma

Friday, March 23, 2012

External columns from Sybase stored procedures

I need to execute several stored procedures on a Sybase server and copy the results to SQL Server 2005 tables. While using an ad-hoc sql statement the "Available External Columns" list is correct, however when using a stored procedure the list is empty. I've tried to work around this a couple of ways without success.

1) DelayedValidation.
I ran the sql from the stored procedure body in the OLE DB Source to set the column list, then turned on DelayValidation for the Data Flow component. When I switch to using a stored procedure it still connects to the Sybase database and removes the column list. Still does this even after turning on DelayedValidation for the sequence container and entire package (the OLE DB source itself does not have the option).

2) Using a variable that changes during runtime.
I copied the sql from the Sybase procedure into the default value of a variable. A script changes it to a procedure at runtime. This provides a column list in design mode but throws the error "The external metadata column collection is out of synchronization with the data source columns. The external metadata column xxxx needs to be removed from the external metadata column collection" and repeats for every column in the list. I know that the column names and data types are identical.

3) Manually updated the external/output columns list.
Was very painful and gave me the same errors.

It seems that DelayedValidation is the route I'm supposed to take, but I don't see how it would be any different during runtime.

Any ideas would be greatly appreciated!

I since learned that the OLE DB data source also has a DelayValidation property, but I still see the same errors with this enabled.
|||Well I think I answered my own question. After switching the connection from the "Native\Sybase" type to ".Net Providers\Sybase" and changing the OLE DB connection to a DataReader I found a new option on the DataFlow property that allowed me to change the sql through an expression at runtime. I may have also needed to turn off the ValidateExternalMetadata property too, not sure yet.

External columns from a Sybase stored procedures

I need to execute several stored procedures on a Sybase server and copy the results to SQL Server 2005 tables. While using an ad-hoc sql statement the "Available External Columns" list is correct, however when using a stored procedure the list is empty. I've tried to work around this a couple of ways without success.

1) DelayedValidation.
I ran the sql from the stored procedure body in the OLE DB Source to set the column list, then turned on DelayValidation for the Data Flow component. When I switch to using a stored procedure it still connects to the Sybase database and removes the column list. Still does this even after turning on DelayedValidation for the sequence container and entire package (the OLE DB source itself does not have the option).

2) Using a variable that changes during runtime.
I copied the sql from the Sybase procedure into the default value of a variable. A script changes it to a procedure at runtime. This provides a column list in design mode but throws the error "The external metadata column collection is out of synchronization with the data source columns. The external metadata column xxxx needs to be removed from the external metadata column collection" and repeats for every column in the list. I know that the column names and data types are identical.

3) Manually updated the external/output columns list.
Was very painful and gave me the same errors.

It seems that DelayedValidation is the route I'm supposed to take, but I don't see how it would be any different during runtime.

Any ideas would be greatly appreciated!

I since learned that the OLE DB data source also has a DelayValidation property, but I still see the same errors with this enabled.
|||Well I think I answered my own question. After switching the connection from the "Native\Sybase" type to ".Net Providers\Sybase" and changing the OLE DB connection to a DataReader I found a new option on the DataFlow property that allowed me to change the sql through an expression at runtime. I may have also needed to turn off the ValidateExternalMetadata property too, not sure yet.

extent locks

hi
Im getting exclusive locks on my table and ext is the resource locked......
can anyone explain me..why do we get ext locks on tables.
regardjust means SQL server has identified a group of 8 pages(extent) for update insert(most likely upadte and insert), create or drop destined for an exclusive lock. More efficient than locking an individual page of a contiguous set of 8 pages|||They are most likely Intent locks and essentially help to prevent things
like deadlocks.
--
Andrew J. Kelly SQL MVP
"san" <anonymous@.discussions.microsoft.com> wrote in message
news:24647640-DE56-4A51-BAE5-74088CD31DE1@.microsoft.com...
> hi,
> Im getting exclusive locks on my table and ext is the resource
locked.......
> can anyone explain me..why do we get ext locks on tables..
> regards
>

Monday, March 19, 2012

Extended SP ?

Hi All,
I want to call an extended proc from a trigger. Is there a way to access the
"Inserted" and "Deleted" tables from the extended proc'
Thanks,
AshkanCould the programming possibly be written using T-SQL? If so, then don't
even pursue the extended proc avenue any further.
"Ashkan Daie" <adaie@.nospam.org> wrote in message
news:%23ehdN4VDFHA.1836@.tk2msftngp13.phx.gbl...
> Hi All,
> I want to call an extended proc from a trigger. Is there a way to access
the
> "Inserted" and "Deleted" tables from the extended proc'
>
> Thanks,
> Ashkan
>|||I wish it could :). That is why I am pursuing the extended proc method.
"JohnnyAppleseed" <someone@.microsoft.com> wrote in message
news:u%23JCU6VDFHA.960@.TK2MSFTNGP09.phx.gbl...
> Could the programming possibly be written using T-SQL? If so, then don't
> even pursue the extended proc avenue any further.
> "Ashkan Daie" <adaie@.nospam.org> wrote in message
> news:%23ehdN4VDFHA.1836@.tk2msftngp13.phx.gbl...
> the
>|||AFAIK, You cannot do this in SQL Server 2000.
Having said that, SQL Server 2005 has flexibility in writing extended stored
procedures in amanged code and even triggers can be written in .NET
languages. These triggers have access to the pseudo tables INSERTED and
DELETED.
HTH,
Vinod Kumar
MCSE, DBA, MCAD, MCSD
http://www.extremeexperts.com
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp
"Ashkan Daie" <adaie@.nospam.org> wrote in message
news:eRhTl9VDFHA.4072@.TK2MSFTNGP10.phx.gbl...
> I wish it could :). That is why I am pursuing the extended proc method.
> "JohnnyAppleseed" <someone@.microsoft.com> wrote in message
> news:u%23JCU6VDFHA.960@.TK2MSFTNGP09.phx.gbl...
access
>|||Hi Ashkan, I hope all is well. Please email me some info, too on extended pr
ocs, db 39482, and Bozbecon, Moose thread, and Rpnzyl threads 9-20. I'm in y
our area, would like to meet for lunch...if you want to. It will be nice.
Sincerely,
C.H.
> Hi All,
> I want to call an extended proc from a trigger. Is there a way to access t
he
> "Inserted" and "Deleted" tables from the extended proc'
>
> Thanks,
> Ashkan
>
User submitted from AEWNET (http://www.aewnet.com/)

Wednesday, March 7, 2012

Expressing a One to Many Relationship in a Single Row

I've two tables.

Table Charge

Table Payments

Charge has a one to many relationship with payments.

I have to transform the data from this new system of normalized tables over to a text file so that it may be read into an old mainframe computer. For each record I need to include the charge details and up to 10 payment details all on the same row.

Like this:

Charge1, ChargeDate, ChargeAmount, Payment1Amount, Payment2Amount, Payment3Amount

Charge2, ChargeDate, ChargeAmount, Payment1Amount, Payment2Amount, Payment3Amount

etc.

If their are less than 10 payments, the row has to be padded.

All of this is going to be DTS'd to a text file.

Is there a query that can handle this?

Simple answer yes:

Without seeing the table structures I can write some code based on these assumptions:

1) when you say Charge1, Charge2 that this is an ID field so I named it ChargeID

2) The Payments table carries the fieldname Payment.

3) Payments table carries the ChargeID as well for reference.

4) Payments carries the payment# represented here as paymentnum

Code Snippet

select distinct chargeID, ChargeDate, ChargeAmount

, pay1.payment [Payment1Amount]

, pay2.payment [Payment2Amount]

, pay3.payment [Payment3Amount]

, pay4.payment [Payment4Amount]

, pay5.payment [Payment5Amount]

, pay6.payment [Payment6Amount]

, pay7.payment [Payment7Amount]

, pay8.payment [Payment8Amount]

, pay9.payment [Payment9Amount]

, pay10.payment [Payment10Amount]

from charge

left join payments [pay1] on pay1.ChargeID = charge.ChargeID and pay1.paymentnum = 1

left join payments [pay2] on pay2.ChargeID = charge.ChargeID and pay2.paymentnum = 2

left join payments [pay3] on pay3.ChargeID = charge.ChargeID and pay3.paymentnum = 3

left join payments [pay4] on pay4.ChargeID = charge.ChargeID and pay4.paymentnum = 4

left join payments [pay5] on pay5.ChargeID = charge.ChargeID and pay5.paymentnum = 5

left join payments [pay6] on pay6.ChargeID = charge.ChargeID and pay6.paymentnum = 6

left join payments [pay7] on pay7.ChargeID = charge.ChargeID and pay7.paymentnum = 7

left join payments [pay8] on pay8.ChargeID = charge.ChargeID and pay8.paymentnum = 8

left join payments [pay9] on pay9.ChargeID = charge.ChargeID and pay9.paymentnum = 9

left join payments [pay10] on pay10.ChargeID = charge.ChargeID and pay10.paymentnum = 10

You can modify this to match your field names. If you don't have a simple paymentnum field, and they need to order by date or something, then I'll or somebody else will have to think a little longer.

right now the empty rows will come out NULL.

However you can represent them as blank or 'no payment' by this:

Code Snippet

case when pay10.payment is null then 'no payment' else pay10.payment end [Payment10Amount]

|||

You could use CTE + row_number() function for with task:

Code Snippet

createtable Charge

(

Id int,

ChargeDate datetime,

ChargeAmount decimal

)

createtable Payments

(

ChargeID int,

PaymentAmount decimal

)

insertinto Charge values(1,'2007-01-01', 1000)

insertinto Payments values(1,10)

insertinto Payments values(1,1)

insertinto Payments values(1,13)

insertinto Payments values(1,12)

insertinto Payments values(1,14)

insertinto Payments values(1,15)

insertinto Payments values(1,17)

insertinto Payments values(1,18)

insertinto Payments values(1,19)

insertinto Charge values(2,'2007-02-01', 100)

insertinto Payments values(2,37)

insertinto Payments values(2,38)

insertinto Payments values(2,49)

with CTE

as

(

--Numerate Payments for each ChargeID

select ChargeID , p.PaymentAmount,

row_number()over(Partitionby ChargeID Orderby ChargeID )as num

from Payments p

)

select

Id, ChargeDate, ChargeAmount

,(selecttop 1 PaymentAmount from CTE where CTE.ChargeID=ID and num=1)as PaymentAmount1

,(selecttop 1 PaymentAmount from CTE where CTE.ChargeID=ID and num=2)as PaymentAmount2

,(selecttop 1 PaymentAmount from CTE where CTE.ChargeID=ID and num=3)as PaymentAmount3

,(selecttop 1 PaymentAmount from CTE where CTE.ChargeID=ID and num=4)as PaymentAmount4

,(selecttop 1 PaymentAmount from CTE where CTE.ChargeID=ID and num=5)as PaymentAmount5

,(selecttop 1 PaymentAmount from CTE where CTE.ChargeID=ID and num=6)as PaymentAmount6

,(selecttop 1 PaymentAmount from CTE where CTE.ChargeID=ID and num=7)as PaymentAmount7

,(selecttop 1 PaymentAmount from CTE where CTE.ChargeID=ID and num=8)as PaymentAmount8

,(selecttop 1 PaymentAmount from CTE where CTE.ChargeID=ID and num=8)as PaymentAmount9

,(selecttop 1 PaymentAmount from CTE where CTE.ChargeID=ID and num=10)as PaymentAmount10

from Charge

Also check output of following query for understanding:

Code Snippet

select ChargeID , p.PaymentAmount,

row_number()over(Partitionby ChargeID Orderby ChargeID )as num

from Payments p

|||

Robert,

Thanks for trying, but the payment table could return up to 10 separate rows.

I've found that the answer seems to be temporary tables and cursors.

Once I get an answer, I'll post it here.

|||

I'm not sure what you mean here I realize that in the Payment table there will be 10 seperate rows. Hence the joining 10 different times the same table.

The structure that we are nomalizing is this correct?

Charge

charge1 amount, payment

Then in the payment table:

Charge1 payment1 $20

Charge1 payment2 $20

Charge1 payment3 $30

... and so on up to 10 times...

the above code will work for this... It is in fact built to handle up to 10 rows in the payment table for one charge.

BTW I was editing when you replied, I added on the section below about changing nulls to 'no payment' and other things you can do with the fields returned.

|||

You can use the following query and simply export it as text file,

Code Snippet

Create Table #charge (

[cid] int ,

[cname] Varchar(100) ,

[cdate] datetime

);

Insert Into #charge Values('1','Charge1','1/1/2007');

Insert Into #charge Values('2','Charge2','1/2/2007');

Insert Into #charge Values('3','Charge3','1/3/2007');

Create Table #payment (

[pid] int ,

[cid] int ,

[pamount] money

);

Insert Into #payment Values('1','1','1000');

Insert Into #payment Values('2','1','10000');

Insert Into #payment Values('3','1','100');

Insert Into #payment Values('4','1','6000');

Insert Into #payment Values('5','1','9000');

Insert Into #payment Values('6','1','100');

Insert Into #payment Values('7','1','100000');

Insert Into #payment Values('8','1','10098');

Insert Into #payment Values('9','1','1000');

Insert Into #payment Values('10','1','1029');

Insert Into #payment Values('16','1','34533');

Insert Into #payment Values('11','2','1000000');

Insert Into #payment Values('12','2','1928');

Insert Into #payment Values('13','2','100');

Insert Into #payment Values('14','2','10000');

Insert Into #payment Values('15','3','100');

Code Snippet

--SQL Server 2000

Select C.Cid,Cname,cdate,pamount into #Temp from #charge C Join #payment P on C.Cid=P.Cid

--Adding the Row Number, Grouped Row Number

Alter table #Temp Add RowId Int Identity(1,1), GroupId int, RowGroup Int

--Finding the Grouped Row Number

Update #Temp

Set

GroupId = RowId - (Select Min(RowID)-1 From #Temp Sub Where #Temp.Cid = Sub.Cid);

--Finding the Row Group

Update #Temp

Set RowGroup = (GroupId-1)/10

--Refine the Grouped Row Number

Update #Temp

Set GroupId = GroupId - (Select Min(GroupId)-1 From #Temp Sub Where #Temp.Cid = Sub.Cid And #Temp.RowGroup = Sub.RowGroup)

--Display the Conetent

Select

RowGroup+1 RowNumber

,CName

,Cdate

,Isnull(Cast(Max(Case When GroupId=1 Then pamount End) as Varchar),'') Payement1Amount

,Isnull(Cast(Max(Case When GroupId=2 Then pamount End) as Varchar),'') Payement2Amount

,Isnull(Cast(Max(Case When GroupId=3 Then pamount End) as Varchar),'') Payement3Amount

,Isnull(Cast(Max(Case When GroupId=4 Then pamount End) as Varchar),'') Payement4Amount

,Isnull(Cast(Max(Case When GroupId=5 Then pamount End) as Varchar),'') Payement5Amount

,Isnull(Cast(Max(Case When GroupId=6 Then pamount End) as Varchar),'') Payement6Amount

,Isnull(Cast(Max(Case When GroupId=7 Then pamount End) as Varchar),'') Payement7Amount

,Isnull(Cast(Max(Case When GroupId=8 Then pamount End) as Varchar),'') Payement8Amount

,Isnull(Cast(Max(Case When GroupId=9 Then pamount End) as Varchar),'') Payement9Amount

,Isnull(Cast(Max(Case When GroupId=10 Then pamount End) as Varchar),'') Payement10Amount

from

#Temp

Group By

CId

,CName

,Cdate

,RowGroup

Code Snippet

-SQL Server 2005

;With Ordered

as

(

Select C.Cid,Cname,cdate,pamount,Row_Number() OVER (Partition By C.Cid Order By C.Cid) GroupRowId from #charge C Join #payment P on C.Cid=P.Cid

)

, Grouped

as

(

Select Cid,Cname,Cdate,pamount,(GroupRowId-1)/10 RowGroup From Ordered

)

, ReGrouped

as

(

Select Cid,Cname,Cdate,pamount,RowGroup,Row_Number() Over(Partition By RowGroup Order By RowGroup) GroupRowId From Grouped

)

Select

RowGroup + 1 RowNumber

,CName

,CDate

,Isnull(Cast([1] as Varchar),'') Payment1Amount

,Isnull(Cast([2] as Varchar),'') Payment2Amount

,Isnull(Cast([3] as Varchar),'') Payment3Amount

,Isnull(Cast([4] as Varchar),'') Payment4Amount

,Isnull(Cast([5] as Varchar),'') Payment5Amount

,Isnull(Cast([6] as Varchar),'') Payment6Amount

,Isnull(Cast([7] as Varchar),'') Payment7Amount

,Isnull(Cast([8] as Varchar),'') Payment8Amount

,Isnull(Cast([9] as Varchar),'') Payment9Amount

,Isnull(Cast([10] as Varchar),'') Payment10Amount

From

ReGrouped

PIVOT

(

Max(pamount) For GroupRowId In ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10])

) as Pvt

|||

WOW.

Thanks for the options guys.

I'll be looking into each one of these.

Sunday, February 26, 2012

Express cannot convert different data types automaticly?

I have a SQL Server 2000 database which works like a charm in my asp app. Joining tables by id columns which are of different data types (eg. int in one table and varchar in the other) is no problem with the SQL Server engine, but Native Client refuses to do so and hands me back an error. Even if columns have a slightly different collation (like Slovenian_CI_AS and SQL_Server_1250_CI_AS) SQL Express native client returns an ERROR?!!! Is it possible that Native client cannot resolve this on its own? Must I change the colattion and datatype on all my tables? Please help!!!!

Peca, developer from Serbia

If you have two columns in two tables, and one is, say PK in one table and FK on the other, then they really should be of the same datatype.

If possible, you should make changes where necessary.

I'm not familiar with Slovenian collations, but different collations may me incompatible between eachother, so there's a chance there could be errors when different collations are used at the same time.

/Kenneth

|||Yes Kenneth, you are right, but the same query works with the SQL SERVER 2000 engine and does not work with EXPRESS database engine. And the problem is that PK's cannot be of the same type in this case. "OLD" sql 2000 engine does not complain but the new one does. I just want to know if this is "solid rock rule" or I can change this behaviour and make him accept these querys?|||

Ah, I see... I haven't tried out those circumstances, so I'm sorry that I don't have a definite answer. Perhaps someone else will chime in with some insights.

/Kenneth

|||

All what you need is to specify collation explicitly in your queries while comparing charater data which collattion differ.

See ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/76763ac8-3e0d-4bbb-aa53-f5e7da021daa.htm

|||

Yes, I know that, but thank you anyway... With the collation I can live, but joining tables with different data types as pk's is a different story. If I say - join the table A with pk datatype int and table B with datatype varchar engine should do the following - join the fields that match ( values 1 -int and "1" varchar) and discard the rest (varchar like "aaa").This really works in SQL Server 2000 but not in Express (returns an error). I am developing databases for years now and I've been working on databases with millions of records and hundreds of tables. This database cannot be normalised more than it is...I'll just stick to 2000 and forget about Express...A BIG thanks to all that replied to y question!!!

|||

>>join the table A with pk datatype int and table B with datatype varchar engine should do the following - join the fields that match ( values 1 -int and "1" varchar) and discard the rest (varchar like "aaa").

Joining two tables throug int field and varchar field, MSSQL would try to convert varchar values into integer value and would generate an error as soon as 'aaa' value reached, unless you specify otherwise in your query.

|||

Agreed. That example has never worked in SQL 2000 either.
the conversion will follow the rules for datatype precedence, and the varchar will be converted to int when implicit conversion comes into play.

So, this is not some new behaviour by Express.

Small demo below from SQL Server 2000: (this is the expected behaviour)

create table #a (pk int not null, a varchar(10) not null)
create table #b (pk varchar(10) not null, b varchar(10) not null)
go
insert #a select 1, 'a'
insert #b select 1, 'b'
insert #b select 'aaa', 'b'
go
select *
from #a join #b
on #a.pk = #b.pk
go


pk a pk b
-- - - -
1 a 1 b

Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value 'aaa' to a column of data type int.

/Kenneth

|||

Kenneth, did I mention that I have the WHERE clausule? Ok, let's end this now and for all ! These are table definitions and bellow is the query that works in SQL 2000 (I can send screenshots to all that do not believe me) and DOES NOT work with EXPRESS (both your and my example).

Your example a bit rewriten:
create table #a (pk int not null, a varchar(10) not null)
create table #b (pk varchar(10) not null, b varchar(10) not null)
go

insert #a select 1, 'a'
insert #a select 2, 'b'
insert #b select 'aaa', 'be'
insert #b select '1', 'c'
insert #b select '2', 'd'

go

select * from #a ,#b
where #a.pk = #b.pk and (#b.b='c' or #b.b='g') and #a.pk in (1)
go

My example that does the same

table :KOMP_REF pk:SIFRA varchar(50)
table :VESTI pk:ID int

they are not referenced in any way (there is no explicit reference between them e.g. constraints, referencial integrity etc.)

query VESTI:
select id,headline,text,date from vesti where id=11
result:
11 heder <FONT face="Courier New".. 2005-12-23 11:51:13.107

query KOMP_REF:
select * from komp_ref
result:
...
lentro 7 4 43 11 81 1 1
11 7 4 127 -1 22 1 1
...

values 81 and 22 are of column SIFRA_KOMP so I believe that row with the value 81 should be excluded from the join by the where clausule in the query bellow

query:
select vesti.id from vesti,komp_ref
where vesti.id=komp_ref.sifra and
(komp_ref.sifra_komp=22 or komp_ref.sifra_komp=64 or komp_ref.sifra_komp=65 or
komp_ref.sifra_komp=91 or komp_ref.sifra_komp=92 or komp_ref.sifra_komp=93)
and vesti.id IN (11)

Express error msg:
Conversion failed when converting the varchar value 'lentro ' to data type int.

Database is copied from sql2000 into express (just copied files without any import procedure etc.)without any changes (I just changed the conn string in my ASP app). I understand all you said but WHY does 2000 do not report an error? Maybe that is the right question? Why is OR operator so confusing for Express? Without the or #b.b='g' even your example works in express but when I add it only SQL2000 returns a recordset? Any comments?!?

|||Sorry KeWin, I wrote Kenneth by mistake :)|||

:) No worries, Kenneth is what my mother calls me also.
(sry for the late reply)

Unfortunately I don't have the ability to try this on Express at the moment, but...
What if you tried rewriting the join ANSI style instead of the old legacy syntax.

select vesti.id
from vesti
join komp_ref
on vesti.id = komp_ref.sifra
and komp_ref.sifra_komp in ('22', '64', '65', '91', '92', '93')
and vesti.id = 11

..see if anything changes..?

/Kenneth

|||unfortunately...no... still reporting the same error... But that is to be expected since the exapmle I gave above has a 100% valid SQL syntax and there are no reasons why it would not work... And did I mention that it works with 2000? ;) (less than 2000 times daaaaa) ... If I accidentaly found a bug (hope not because it would be a huuuuuuuuge one) the boys and girls from MS owe me a beer :) thanx 4 all Kewin!

Express cannot convert different data types automaticly?

I have a SQL Server 2000 database which works like a charm in my asp app. Joining tables by id columns which are of different data types (eg. int in one table and varchar in the other) is no problem with the SQL Server engine, but Native Client refuses to do so and hands me back an error. Even if columns have a slightly different collation (like Slovenian_CI_AS and SQL_Server_1250_CI_AS) SQL Express native client returns an ERROR?!!! Is it possible that Native client cannot resolve this on its own? Must I change the colattion and datatype on all my tables? Please help!!!!

Peca, developer from Serbia

If you have two columns in two tables, and one is, say PK in one table and FK on the other, then they really should be of the same datatype.

If possible, you should make changes where necessary.

I'm not familiar with Slovenian collations, but different collations may me incompatible between eachother, so there's a chance there could be errors when different collations are used at the same time.

/Kenneth

|||Yes Kenneth, you are right, but the same query works with the SQL SERVER 2000 engine and does not work with EXPRESS database engine. And the problem is that PK's cannot be of the same type in this case. "OLD" sql 2000 engine does not complain but the new one does. I just want to know if this is "solid rock rule" or I can change this behaviour and make him accept these querys?|||

Ah, I see... I haven't tried out those circumstances, so I'm sorry that I don't have a definite answer. Perhaps someone else will chime in with some insights.

/Kenneth

|||

All what you need is to specify collation explicitly in your queries while comparing charater data which collattion differ.

See ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/76763ac8-3e0d-4bbb-aa53-f5e7da021daa.htm

|||

Yes, I know that, but thank you anyway... With the collation I can live, but joining tables with different data types as pk's is a different story. If I say - join the table A with pk datatype int and table B with datatype varchar engine should do the following - join the fields that match ( values 1 -int and "1" varchar) and discard the rest (varchar like "aaa").This really works in SQL Server 2000 but not in Express (returns an error). I am developing databases for years now and I've been working on databases with millions of records and hundreds of tables. This database cannot be normalised more than it is...I'll just stick to 2000 and forget about Express...A BIG thanks to all that replied to y question!!!

|||

>>join the table A with pk datatype int and table B with datatype varchar engine should do the following - join the fields that match ( values 1 -int and "1" varchar) and discard the rest (varchar like "aaa").

Joining two tables throug int field and varchar field, MSSQL would try to convert varchar values into integer value and would generate an error as soon as 'aaa' value reached, unless you specify otherwise in your query.

|||

Agreed. That example has never worked in SQL 2000 either.
the conversion will follow the rules for datatype precedence, and the varchar will be converted to int when implicit conversion comes into play.

So, this is not some new behaviour by Express.

Small demo below from SQL Server 2000: (this is the expected behaviour)

create table #a (pk int not null, a varchar(10) not null)
create table #b (pk varchar(10) not null, b varchar(10) not null)
go
insert #a select 1, 'a'
insert #b select 1, 'b'
insert #b select 'aaa', 'b'
go
select *
from #a join #b
on #a.pk = #b.pk
go


pk a pk b
-- - - -
1 a 1 b

Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value 'aaa' to a column of data type int.

/Kenneth

|||

Kenneth, did I mention that I have the WHERE clausule? Ok, let's end this now and for all ! These are table definitions and bellow is the query that works in SQL 2000 (I can send screenshots to all that do not believe me) and DOES NOT work with EXPRESS (both your and my example).

Your example a bit rewriten:
create table #a (pk int not null, a varchar(10) not null)
create table #b (pk varchar(10) not null, b varchar(10) not null)
go

insert #a select 1, 'a'
insert #a select 2, 'b'
insert #b select 'aaa', 'be'
insert #b select '1', 'c'
insert #b select '2', 'd'

go

select * from #a ,#b
where #a.pk = #b.pk and (#b.b='c' or #b.b='g') and #a.pk in (1)
go

My example that does the same

table :KOMP_REF pk:SIFRA varchar(50)
table :VESTI pk:ID int

they are not referenced in any way (there is no explicit reference between them e.g. constraints, referencial integrity etc.)

query VESTI:
select id,headline,text,date from vesti where id=11
result:
11 heder <FONT face="Courier New".. 2005-12-23 11:51:13.107

query KOMP_REF:
select * from komp_ref
result:
...
lentro 7 4 43 11 81 1 1
11 7 4 127 -1 22 1 1
...

values 81 and 22 are of column SIFRA_KOMP so I believe that row with the value 81 should be excluded from the join by the where clausule in the query bellow

query:
select vesti.id from vesti,komp_ref
where vesti.id=komp_ref.sifra and
(komp_ref.sifra_komp=22 or komp_ref.sifra_komp=64 or komp_ref.sifra_komp=65 or
komp_ref.sifra_komp=91 or komp_ref.sifra_komp=92 or komp_ref.sifra_komp=93)
and vesti.id IN (11)

Express error msg:
Conversion failed when converting the varchar value 'lentro ' to data type int.

Database is copied from sql2000 into express (just copied files without any import procedure etc.)without any changes (I just changed the conn string in my ASP app). I understand all you said but WHY does 2000 do not report an error? Maybe that is the right question? Why is OR operator so confusing for Express? Without the or #b.b='g' even your example works in express but when I add it only SQL2000 returns a recordset? Any comments?!?

|||Sorry KeWin, I wrote Kenneth by mistake :)|||

:) No worries, Kenneth is what my mother calls me also.
(sry for the late reply)

Unfortunately I don't have the ability to try this on Express at the moment, but...
What if you tried rewriting the join ANSI style instead of the old legacy syntax.

select vesti.id
from vesti
join komp_ref
on vesti.id = komp_ref.sifra
and komp_ref.sifra_komp in ('22', '64', '65', '91', '92', '93')
and vesti.id = 11

..see if anything changes..?

/Kenneth

|||unfortunately...no... still reporting the same error... But that is to be expected since the exapmle I gave above has a 100% valid SQL syntax and there are no reasons why it would not work... And did I mention that it works with 2000? ;) (less than 2000 times daaaaa) ... If I accidentaly found a bug (hope not because it would be a huuuuuuuuge one) the boys and girls from MS owe me a beer :) thanx 4 all Kewin!

Friday, February 24, 2012

exporting/importing tables

Hi there.
What is the best way to export/import a SQL table from one SQL server on a
computer to another computer.
I am a contractor, working on my laptop, with a company, that will not allow
me to hook my laptop up to their network.
I keep a 'copy' of what is on their SQL server, and am constantly updating,
back and forth between my laptop and their server.
Because I didn't know a better way, I have been exporting to an access file
on disk, then importing back into SQL on the other computer.
Generally this works okay, but lately I have been running into some problems
with datatypes being converted etc.
I'm assuming there is a much better way to do this.
Am I right?
Thanks in advance!
amberSimplest is to use a SQL Backup file... If this is production system, then
there are probably backup files already been done regularly that you should
be able to get acces to... If it's a development dataabse, then just do the
backup yourself, to a disk file. on a network UNC of your choice, where you
can copy the file to whatever medium you are using to get it to your laptop,
then just "restore" the backup to the SQL Server Database on your laptop.
Two gotchas to be aware of, When you select Restore in the SQL Enterprise
Mgr GUI, go to the options tab, and check the "Force Restore over existing
database" option checkbox, and type over the file locations on the far right
column, with the physical file locations on your laptop.
"amber" wrote:

> Hi there.
> What is the best way to export/import a SQL table from one SQL server on a
> computer to another computer.
> I am a contractor, working on my laptop, with a company, that will not all
ow
> me to hook my laptop up to their network.
> I keep a 'copy' of what is on their SQL server, and am constantly updating
,
> back and forth between my laptop and their server.
> Because I didn't know a better way, I have been exporting to an access fil
e
> on disk, then importing back into SQL on the other computer.
> Generally this works okay, but lately I have been running into some proble
ms
> with datatypes being converted etc.
> I'm assuming there is a much better way to do this.
> Am I right?
> Thanks in advance!
> amber
>|||If you are talking about data, then take a look to BCP utility or DTS, to
create csv files.
AMB
"amber" wrote:

> Hi there.
> What is the best way to export/import a SQL table from one SQL server on a
> computer to another computer.
> I am a contractor, working on my laptop, with a company, that will not all
ow
> me to hook my laptop up to their network.
> I keep a 'copy' of what is on their SQL server, and am constantly updating
,
> back and forth between my laptop and their server.
> Because I didn't know a better way, I have been exporting to an access fil
e
> on disk, then importing back into SQL on the other computer.
> Generally this works okay, but lately I have been running into some proble
ms
> with datatypes being converted etc.
> I'm assuming there is a much better way to do this.
> Am I right?
> Thanks in advance!
> amber
>|||You can script out the table. Create insert statements for the data using th
e
following script:
http://vyaskn.tripod.com/code.htm#inserts
Then run the table create script and data insert script on your destination
computer.
HTH
ZULFIQAR SYED
"Alejandro Mesa" wrote:
> If you are talking about data, then take a look to BCP utility or DTS, to
> create csv files.
>
> AMB
> "amber" wrote:
>|||Script your data with www.sqlscripter.com
There's an option like "Insert new, update existing" records ...
Thomas
"amber" wrote:

> Hi there.
> What is the best way to export/import a SQL table from one SQL server on a
> computer to another computer.
> I am a contractor, working on my laptop, with a company, that will not all
ow
> me to hook my laptop up to their network.
> I keep a 'copy' of what is on their SQL server, and am constantly updating
,
> back and forth between my laptop and their server.
> Because I didn't know a better way, I have been exporting to an access fil
e
> on disk, then importing back into SQL on the other computer.
> Generally this works okay, but lately I have been running into some proble
ms
> with datatypes being converted etc.
> I'm assuming there is a much better way to do this.
> Am I right?
> Thanks in advance!
> amber
>

Exporting XML using bcp

I am exporting XML query results from a stored procedure using bcp. The query is pulling data from several tables and create XML using FOR XML EXPLICIT.

The following is the bcp command used to export the result:

bcp "exec sprocname" queryout output.xml -w -T

The resulting output file appears to limit the number of charcters per line to 2033 characters and cut the data into the next row regardless whether the 2033th character is in the middle of an xml tag. As a result the resulting xml output become unreadable.

Any suggestions would be much appreciated.

I hope you are using SQL2005. If so, just add ,TYPE at the end of your FOR XML query as

SELECT ...

FOR EXPLICIT, TYPE

Exporting XML using bcp

I am exporting XML query results from a stored procedure using bcp. The query is pulling data from several tables and create XML using FOR XML EXPLICIT.

The following is the bcp command used to export the result:

bcp "exec sprocname" queryout output.xml -w -T

The resulting output file appears to limit the number of charcters per line to 2033 characters and cut the data into the next row regardless whether the 2033th character is in the middle of an xml tag. As a result the resulting xml output become unreadable.

Any suggestions would be much appreciated.

I hope you are using SQL2005. If so, just add ,TYPE at the end of your FOR XML query as

SELECT ...

FOR EXPLICIT, TYPE

Exporting views

I'm trying to export views from one server to another but
it exports views as tables...
Any suggestion?
Thanx in advance
MartynCould you explain what you're doing? SQL Server doesn't export views as
tables. What tool are you using?
Did yuo try to simply script the views using the Generate SQL Script option
from SQL Enterprise Manager?
--
Brian
"Martyn" <anonymous@.discussions.microsoft.com> wrote in message
news:047601c399d3$8a962230$a601280a@.phx.gbl...
> I'm trying to export views from one server to another but
> it exports views as tables...
> Any suggestion?
> Thanx in advance
> Martyn|||I used SQL Server2000 Enterprise mangaer.
From one server, I selected export data and copy tables
and views option. Then selected 4 views which lies in
view folder but it exported as table at the destination
server.
>--Original Message--
>Could you explain what you're doing? SQL Server doesn't
export views as
>tables. What tool are you using?
>Did yuo try to simply script the views using the
Generate SQL Script option
>from SQL Enterprise Manager?
>--
>Brian
>
>"Martyn" <anonymous@.discussions.microsoft.com> wrote in
message
>news:047601c399d3$8a962230$a601280a@.phx.gbl...
>> I'm trying to export views from one server to another
but
>> it exports views as tables...
>> Any suggestion?
>> Thanx in advance
>> Martyn
>
>.
>|||It sounds like you might be doing this using the DTS Export
Wizard. When the dialog box comes up to select what to copy
and you select the option for "copy table(s) and view(s)
from the source database, you will be copying data not
copying objects. If you need the views to be copied as views
- not just the data - you need to use the option for "copy
objects and data between SQL Server databases"
-Sue
On Thu, 23 Oct 2003 19:43:43 -0700, "Martyn"
<anonymous@.discussions.microsoft.com> wrote:
>I used SQL Server2000 Enterprise mangaer.
>From one server, I selected export data and copy tables
>and views option. Then selected 4 views which lies in
>view folder but it exported as table at the destination
>server.
>>--Original Message--
>>Could you explain what you're doing? SQL Server doesn't
>export views as
>>tables. What tool are you using?
>>Did yuo try to simply script the views using the
>Generate SQL Script option
>>from SQL Enterprise Manager?
>>--
>>Brian
>>
>>"Martyn" <anonymous@.discussions.microsoft.com> wrote in
>message
>>news:047601c399d3$8a962230$a601280a@.phx.gbl...
>> I'm trying to export views from one server to another
>but
>> it exports views as tables...
>> Any suggestion?
>> Thanx in advance
>> Martyn
>>
>>.

Sunday, February 19, 2012

Exporting to textfiles

Hi,
I have a SQL 2000 db with 140 tables. I want to export all tables to
textfiles. If I use Tool | Export data I only can export one table each
time.
Is there any way to export all tables automatically (I want the resulting
textfiles to have the same name as the original db table)?
Regards
PO
Hi,
You can write a BCP OUT command for Information_schema.Tables
Execute the below script in Query analyzer with Text result. Paste the
output of the result in a new Query window and execute. This will export the
table data to text files in c:\backup folder with the table name as the text
file name.
use <dbname>
go
set quoted_identifier off
select 'master..xp_cmdshell '+"'"+bcp pay..'+table_name+' out
c:\backup\'+table_name+'.txt -Usa -Phari -Sa266uss\harisql -c'+"'"
+char(10)+'go' from information_schema.tables where +table_type='BASE TABLE'
Thanks
Hari
MCDBA
"PO" <po> wrote in message news:e1$nZ0YaEHA.1048@.tk2msftngp13.phx.gbl...
> Hi,
> I have a SQL 2000 db with 140 tables. I want to export all tables to
> textfiles. If I use Tool | Export data I only can export one table each
> time.
> Is there any way to export all tables automatically (I want the resulting
> textfiles to have the same name as the original db table)?
> Regards
> PO
>

Exporting to Multiple Excel worksheets

I am having trouble exporting my SRS data to multiple Excel worksheets.
I have four tables. I want each of these tables to appear on a
different worksheet even if there is no data for it. For one of my
queries, there was only data for 3 of these tables. First I selected
"Insert a Page Break after this table" for all of my Table properties.
When I exported this output to Excel, it only showed me 3 worksheets.
But I want it to always show me all four worksheets even if there is no
data for that table. And I believe it should still show me something
on this 4th worksheet because in SRS on each table's property I entered
in "No Data Available" for the NoRows table property. Instead what it
does is the Excel file includes this 4th table on the same worksheet as
one of the other tables. And I clearly see the text "No Data
Available", but it's not on its own page.
So again, how do I automatically have all 4 tables show up on 4
different tabs (worksheets).Try selecting "Insert a Page Break Before this table" for your 4th
table and see what happens.
Mike|||I tried this, but this didn't fix it either.
"Bassist695" wrote:
> Try selecting "Insert a Page Break Before this table" for your 4th
> table and see what happens.
> Mike
>|||Try to use GROUP in the layout design. Each group will be distributed as
individual worksheet accordingly.
ironryan77@.gmail.com wrote:
>I am having trouble exporting my SRS data to multiple Excel worksheets.
> I have four tables. I want each of these tables to appear on a
>different worksheet even if there is no data for it. For one of my
>queries, there was only data for 3 of these tables. First I selected
>"Insert a Page Break after this table" for all of my Table properties.
>When I exported this output to Excel, it only showed me 3 worksheets.
>But I want it to always show me all four worksheets even if there is no
>data for that table. And I believe it should still show me something
>on this 4th worksheet because in SRS on each table's property I entered
>in "No Data Available" for the NoRows table property. Instead what it
>does is the Excel file includes this 4th table on the same worksheet as
>one of the other tables. And I clearly see the text "No Data
>Available", but it's not on its own page.
>So again, how do I automatically have all 4 tables show up on 4
>different tabs (worksheets).
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-reporting/200603/1|||Just return a space character on any of the table fields so that RS will
thing that the table needs to be printed on the fourth sheet as well. If you
have empty it wont return but just insert a space if no records are
available.
Amarnath.
"ironryan77@.gmail.com" wrote:
> I am having trouble exporting my SRS data to multiple Excel worksheets.
> I have four tables. I want each of these tables to appear on a
> different worksheet even if there is no data for it. For one of my
> queries, there was only data for 3 of these tables. First I selected
> "Insert a Page Break after this table" for all of my Table properties.
> When I exported this output to Excel, it only showed me 3 worksheets.
> But I want it to always show me all four worksheets even if there is no
> data for that table. And I believe it should still show me something
> on this 4th worksheet because in SRS on each table's property I entered
> in "No Data Available" for the NoRows table property. Instead what it
> does is the Excel file includes this 4th table on the same worksheet as
> one of the other tables. And I clearly see the text "No Data
> Available", but it's not on its own page.
> So again, how do I automatically have all 4 tables show up on 4
> different tabs (worksheets).
>|||I have tried all of the above suggestions, but none of them work. Have any
of you ever tried to do what I'm doing? Regarding Amarnath's response, it
would not be easy for me to insert a space since I am filtering the data from
one table. In other words, my SP selects data into one table which is then
filtered in SRS based on the grouping. Unless there is a way to form an
expression so that it inserts a space. Is this possible?
Regarding Frog's post, I created a group for this table and set the filter,
but this did not work either. And I have tried adding header and footer
where all of the footers contain the text "End of Record", but for this one
table with no data in it, neither header nor footer display. Only the text I
enter into the NoRows property displays. If I remove the text from NoRows
then there is a big space on that part of the worksheet, but I still only
have 3 total worksheets.
"Amarnath" wrote:
> Just return a space character on any of the table fields so that RS will
> thing that the table needs to be printed on the fourth sheet as well. If you
> have empty it wont return but just insert a space if no records are
> available.
> Amarnath.
> "ironryan77@.gmail.com" wrote:
> > I am having trouble exporting my SRS data to multiple Excel worksheets.
> > I have four tables. I want each of these tables to appear on a
> > different worksheet even if there is no data for it. For one of my
> > queries, there was only data for 3 of these tables. First I selected
> > "Insert a Page Break after this table" for all of my Table properties.
> >
> > When I exported this output to Excel, it only showed me 3 worksheets.
> > But I want it to always show me all four worksheets even if there is no
> > data for that table. And I believe it should still show me something
> > on this 4th worksheet because in SRS on each table's property I entered
> > in "No Data Available" for the NoRows table property. Instead what it
> > does is the Excel file includes this 4th table on the same worksheet as
> > one of the other tables. And I clearly see the text "No Data
> > Available", but it's not on its own page.
> >
> > So again, how do I automatically have all 4 tables show up on 4
> > different tabs (worksheets).
> >
> >

Friday, February 17, 2012

exporting to CSV

Hi,

I have a bunch of stored procedures (some using temp tables) which give
out tables which are then used in crystal to give out reports. These
stored procs are run dynamically depending on values users select on
forms

Some people instead of reports want Comma Seperated Files (CSVs). I am
trying to find a good way of outputting to csv with using either sql
server or ASP. I tried two ways but none of them were ideal

1st method
first way i tried was creating a record set in asp and then using the
following to output the data in a comma delimited row and writing to
file.
Response.Write RecordSet.GetString(,,", ",vbCrLf,"")
The problem with the above was with data sets greater than 10,000
records the processing time increases exponentially because of memory
usage ( i found other people with the same problem)

So i tried the following
2nd method
I used bcp using the master.dbo.xp_cmdshell command to output the
csv. The problem with that is that the bcp executes the stored proc
three times and also doesnot give out column headers. So i had to run
the stored proc once in ASP and get the headers from the record set and
store it to a text file and then run the stored proc in bcp and send
the output to a csv file. Then merge the two files into a third file.
The problem with this method is that it takes around 4 times as long to
run as just the stored proceedure and also i have to create 3 files
instead of one.

I would appreciate any suggestions you have to output the csv from a
stored proc in sql server. Note users have to do this dynamically when
they submit a form so cant use the query analyzer or enterprise manager
tools.

Thanks for your time and help
:)use DTS export wizard...then schedule it...
Katie wrote:

Quote:

Originally Posted by

Hi,
>
I have a bunch of stored procedures (some using temp tables) which give
out tables which are then used in crystal to give out reports. These
stored procs are run dynamically depending on values users select on
forms
>
Some people instead of reports want Comma Seperated Files (CSVs). I am
trying to find a good way of outputting to csv with using either sql
server or ASP. I tried two ways but none of them were ideal
>
1st method
first way i tried was creating a record set in asp and then using the
following to output the data in a comma delimited row and writing to
file.
Response.Write RecordSet.GetString(,,", ",vbCrLf,"")
The problem with the above was with data sets greater than 10,000
records the processing time increases exponentially because of memory
usage ( i found other people with the same problem)
>
So i tried the following
2nd method
I used bcp using the master.dbo.xp_cmdshell command to output the
csv. The problem with that is that the bcp executes the stored proc
three times and also doesnot give out column headers. So i had to run
the stored proc once in ASP and get the headers from the record set and
store it to a text file and then run the stored proc in bcp and send
the output to a csv file. Then merge the two files into a third file.
The problem with this method is that it takes around 4 times as long to
run as just the stored proceedure and also i have to create 3 files
instead of one.
>
I would appreciate any suggestions you have to output the csv from a
stored proc in sql server. Note users have to do this dynamically when
they submit a form so cant use the query analyzer or enterprise manager
tools.
>
Thanks for your time and help
:)

|||How would that work if i want the user to enter values in a form and
then wen they click submit run a stored proc using the values they
entered as params and output for them a csv file.

Cimode wrote:

Quote:

Originally Posted by

use DTS export wizard...then schedule it...
Katie wrote:

Quote:

Originally Posted by

Hi,

I have a bunch of stored procedures (some using temp tables) which give
out tables which are then used in crystal to give out reports. These
stored procs are run dynamically depending on values users select on
forms

Some people instead of reports want Comma Seperated Files (CSVs). I am
trying to find a good way of outputting to csv with using either sql
server or ASP. I tried two ways but none of them were ideal

1st method
first way i tried was creating a record set in asp and then using the
following to output the data in a comma delimited row and writing to
file.
Response.Write RecordSet.GetString(,,", ",vbCrLf,"")
The problem with the above was with data sets greater than 10,000
records the processing time increases exponentially because of memory
usage ( i found other people with the same problem)

So i tried the following
2nd method
I used bcp using the master.dbo.xp_cmdshell command to output the
csv. The problem with that is that the bcp executes the stored proc
three times and also doesnot give out column headers. So i had to run
the stored proc once in ASP and get the headers from the record set and
store it to a text file and then run the stored proc in bcp and send
the output to a csv file. Then merge the two files into a third file.
The problem with this method is that it takes around 4 times as long to
run as just the stored proceedure and also i have to create 3 files
instead of one.

I would appreciate any suggestions you have to output the csv from a
stored proc in sql server. Note users have to do this dynamically when
they submit a form so cant use the query analyzer or enterprise manager
tools.

Thanks for your time and help
:)

|||Katie wrote:

Quote:

Originally Posted by

How would that work if i want the user to enter values in a form and
then wen they click submit run a stored proc using the values they
entered as params and output for them a csv file.


You can write a custom DTS package that is called from a stored proc.
Parameters to that stored proc will be the parameters you want to query
on. The stored proc will set global DTS variables based on these
parameters and DTS will use these variables to filter out the unwanted
records. You'll probably want a good book on DTS as this sort of thing
can be a bear for the uninitiated. SQL Server 2000 DTS Step By Step by
Carl Rabeler worked for me!

Cheers,
Brian

--
================================================== =================

Brian Peasland
oracle_dba@.nospam.peasland.net
http://www.peasland.net
Remove the "nospam." from the email address to email me.

"I can give it to you cheap, quick, and good.
Now pick two out of the three" - Unknown|||What you can do is generate your DTS package and schedule it. As a
result you will get an identifier for that package. You may then call
the package from some user event.

Katie wrote:

Quote:

Originally Posted by

How would that work if i want the user to enter values in a form and
then wen they click submit run a stored proc using the values they
entered as params and output for them a csv file.
>
Cimode wrote:

Quote:

Originally Posted by

use DTS export wizard...then schedule it...
Katie wrote:

Quote:

Originally Posted by

Hi,
>
I have a bunch of stored procedures (some using temp tables) which give
out tables which are then used in crystal to give out reports. These
stored procs are run dynamically depending on values users select on
forms
>
Some people instead of reports want Comma Seperated Files (CSVs). I am
trying to find a good way of outputting to csv with using either sql
server or ASP. I tried two ways but none of them were ideal
>
1st method
first way i tried was creating a record set in asp and then using the
following to output the data in a comma delimited row and writing to
file.
Response.Write RecordSet.GetString(,,", ",vbCrLf,"")
The problem with the above was with data sets greater than 10,000
records the processing time increases exponentially because of memory
usage ( i found other people with the same problem)
>
So i tried the following
2nd method
I used bcp using the master.dbo.xp_cmdshell command to output the
csv. The problem with that is that the bcp executes the stored proc
three times and also doesnot give out column headers. So i had to run
the stored proc once in ASP and get the headers from the record set and
store it to a text file and then run the stored proc in bcp and send
the output to a csv file. Then merge the two files into a third file.
The problem with this method is that it takes around 4 times as long to
run as just the stored proceedure and also i have to create 3 files
instead of one.
>
I would appreciate any suggestions you have to output the csv from a
stored proc in sql server. Note users have to do this dynamically when
they submit a form so cant use the query analyzer or enterprise manager
tools.
>
Thanks for your time and help
:)

Exporting to Access

Hello, I occasionally have to take all the tables from a particular
database and dump the data into Access tables. When I use the wizard to do
this, I find that the tables in access must be empty prior to me stepping
through the wizard to export the data or otheriwse is kick the transaction
out as duplicate. I have been going into access and running a query for
each of the tables to delete all of the data.
Is there a way that I can do this all within SQL? Can I write the commands
to initialize those tables in access in some sort of SQL Proc?
Your suggestions would be greatly appreciated!!!!!!!!!How do you export data from sql server to Access ? Try
DTS export wizard tool available from sql server
enterprise Manager. It will let you delete all rows from
Access tables and then load data from sql to access. You
can also save the export options in a DTS package which
you can simply execute next time when you need to export
data. You can also schedule it to run on regular interval.
You can find more details about DTS packages in sql server
BOL, or post specific questions here.
hth.
>--Original Message--
>Hello, I occasionally have to take all the tables from a
particular
>database and dump the data into Access tables. When I
use the wizard to do
>this, I find that the tables in access must be empty
prior to me stepping
>through the wizard to export the data or otheriwse is
kick the transaction
>out as duplicate. I have been going into access and
running a query for
>each of the tables to delete all of the data.
>Is there a way that I can do this all within SQL? Can I
write the commands
>to initialize those tables in access in some sort of SQL
Proc?
>Your suggestions would be greatly appreciated!!!!!!!!!
>.
>|||Thanks

Exporting the Table Structure...

Hye guys,
I want 2 export the field names and their properties of my tables to a file by which I would be able 2 print it , Study it and share it with my other friends... for discussions...

Which tool can be used 2 export the table stture in a printable format?

Kabin

Why don't you create a Diagram?

|||

Hi Kabin,

You have a few options depending on what you're looking for. You don't mention which version of SQL Server you have, so I'll try to provide instructions for 2000 and 2005 versions.

1. Create a script of the table's definition.

From Management Studio in Object Explorer, right-click the table and point to Script Table as and then select Create to and choose to save it to a file.

or for SQL Server 2000

From Query Analyzer, right-click the table and select Script Object to File as and then select Create.

2. Use sp_help.

From either Management Studio or Query Analyzer run the following statement.

EXEC sp_help ('your_table_name')

3. Create a database diagram.

See Books Online topics for creating database diagrams. (although your print options are somewhat limited with this).

Regards,

Gail

|||

Hi guys,
well I first tried creating diagram and then printing it. It was really litte bit some tedious work as I can only print from it. I can export it to excel or even notepad for formatting also. Diagram gave me really limited feature which is not sufficient.

Secondly I tried with SP_help. It also didn't worked.

THirdlr I tried with creating script for the object or table that worked fine but not also fully as i wanted. I just wanted the column name in left side and its properties in formatted way in right side in 2 column format but well Script also provided me some help.

Thanks Guys.

|||

Actually, sp_help should produce the information you want. Saying "It didn't work" doesn't give us much to go on to help you. Did you get an error message? If so, what was it?

You might want to query the table metadata by using the system tables (in SS 2000) or the catalog views (in SS2005). For example, in SQL Server 2005, you can write a query like the following example to return the table and column names and their properties.

SELECT o.name AS TableName,
c.name AS ColumnName,
t.name AS DataType,
c.Max_Length,
c.Precision,
c.Scale
FROM sys.objects AS o
INNER JOIN sys.columns AS c ON o.object_id = c.object_id
INNER JOIN sys.types AS t ON c.user_type_id = t.user_type_id
WHERE type = 'U'

And here's an equivalent query in SQL Server 2000.

SELECT o.name AS TableName,
c.name AS ColumnName,
t.name AS DataType,
c.length,
c.xprec,
c.xscale
FROM sysobjects AS o
INNER JOIN syscolumns AS c ON o.id = c.id
INNER JOIN systypes AS t ON c.usertype = t.usertype
WHERE o.type = 'U'

I only selected a few column properties. To see all the columns available in the system tables/views, see Books Online.

Regards,

Gail

|||

hi..Guys..

Thanks a lot ur suggestions helped me alot man...

|||

You can get the structure from the query analyser by the command --> sp_help tablename

Exporting the Table Structure...

Hye guys,
I want 2 export the field names and their properties of my tables to a file by which I would be able 2 print it , Study it and share it with my other friends... for discussions...

Which tool can be used 2 export the table stture in a printable format?

Kabin

Why don't you create a Diagram?

|||

Hi Kabin,

You have a few options depending on what you're looking for. You don't mention which version of SQL Server you have, so I'll try to provide instructions for 2000 and 2005 versions.

1. Create a script of the table's definition.

From Management Studio in Object Explorer, right-click the table and point to Script Table as and then select Create to and choose to save it to a file.

or for SQL Server 2000

From Query Analyzer, right-click the table and select Script Object to File as and then select Create.

2. Use sp_help.

From either Management Studio or Query Analyzer run the following statement.

EXEC sp_help ('your_table_name')

3. Create a database diagram.

See Books Online topics for creating database diagrams. (although your print options are somewhat limited with this).

Regards,

Gail

|||

Hi guys,
well I first tried creating diagram and then printing it. It was really litte bit some tedious work as I can only print from it. I can export it to excel or even notepad for formatting also. Diagram gave me really limited feature which is not sufficient.

Secondly I tried with SP_help. It also didn't worked.

THirdlr I tried with creating script for the object or table that worked fine but not also fully as i wanted. I just wanted the column name in left side and its properties in formatted way in right side in 2 column format but well Script also provided me some help.

Thanks Guys.

|||

Actually, sp_help should produce the information you want. Saying "It didn't work" doesn't give us much to go on to help you. Did you get an error message? If so, what was it?

You might want to query the table metadata by using the system tables (in SS 2000) or the catalog views (in SS2005). For example, in SQL Server 2005, you can write a query like the following example to return the table and column names and their properties.

SELECT o.name AS TableName,
c.name AS ColumnName,
t.name AS DataType,
c.Max_Length,
c.Precision,
c.Scale
FROM sys.objects AS o
INNER JOIN sys.columns AS c ON o.object_id = c.object_id
INNER JOIN sys.types AS t ON c.user_type_id = t.user_type_id
WHERE type = 'U'

And here's an equivalent query in SQL Server 2000.

SELECT o.name AS TableName,
c.name AS ColumnName,
t.name AS DataType,
c.length,
c.xprec,
c.xscale
FROM sysobjects AS o
INNER JOIN syscolumns AS c ON o.id = c.id
INNER JOIN systypes AS t ON c.usertype = t.usertype
WHERE o.type = 'U'

I only selected a few column properties. To see all the columns available in the system tables/views, see Books Online.

Regards,

Gail

|||

hi..Guys..

Thanks a lot ur suggestions helped me alot man...

|||

You can get the structure from the query analyser by the command --> sp_help tablename

Exporting tables to another location.

Dear reader,
In SQL-server 2005 what are the preferred method to transport tables from
one database to another database, if those databases are not connected ? (To
copy the content).
In SQL-server 2000 I used sp_generate_inserts (Copyright © 2002 Narayana
Vyas Kondreddi. All rights reserved.) a lot to export smal tables to
transport them and import them in other locations. For most situations this
does also work in SQL-server 2005.
But what if this doesn't work, because of the size (length of records or
number of records in the table), or because of datatypes. What are preferred
methods to export a database to something that can be transported (a file
which is fairly compact) and then imported in another database ?
Thanks for your time and attention,
Ben BrugmanOn May 22, 1:32 pm, "ben brugman" <b...@.niethier.nl> wrote:
> Dear reader,
> In SQL-server 2005 what are the preferred method to transport tables from
> one database to another database, if those databases are not connected ? =(To
> copy the content).
> In SQL-server 2000 I used sp_generate_inserts (Copyright =A9 2002 Narayana
> Vyas Kondreddi. All rights reserved.) a lot to export smal tables to
> transport them and import them in other locations. For most situations th=is
> does also work in SQL-server 2005.
> But what if this doesn't work, because of the size (length of records or
> number of records in the table), or because of datatypes. What are prefer=red
> methods to export a database to something that can be transported (a file
> which is fairly compact) and then imported in another database ?
> Thanks for your time and attention,
> Ben Brugman
1=2E At Source Use BCP OUT to text file with Delimiter , Zip ( If file
is huge) , Upload through FTP At Destination FTP Download, UnZIP, BCP
IN (or BULK INSERT)
2=2E use SSIS or DTS

Exporting tables to another location.

Dear reader,
In SQL-server 2005 what are the preferred method to transport tables from
one database to another database, if those databases are not connected ? (To
copy the content).
In SQL-server 2000 I used sp_generate_inserts (Copyright 2002 Narayana
Vyas Kondreddi. All rights reserved.) a lot to export smal tables to
transport them and import them in other locations. For most situations this
does also work in SQL-server 2005.
But what if this doesn't work, because of the size (length of records or
number of records in the table), or because of datatypes. What are preferred
methods to export a database to something that can be transported (a file
which is fairly compact) and then imported in another database ?
Thanks for your time and attention,
Ben Brugman
On May 22, 1:32 pm, "ben brugman" <b...@.niethier.nl> wrote:
> Dear reader,
> In SQL-server 2005 what are the preferred method to transport tables from
> one database to another database, if those databases are not connected ? (To
> copy the content).
> In SQL-server 2000 I used sp_generate_inserts (Copyright 2002 Narayana
> Vyas Kondreddi. All rights reserved.) a lot to export smal tables to
> transport them and import them in other locations. For most situations this
> does also work in SQL-server 2005.
> But what if this doesn't work, because of the size (length of records or
> number of records in the table), or because of datatypes. What are preferred
> methods to export a database to something that can be transported (a file
> which is fairly compact) and then imported in another database ?
> Thanks for your time and attention,
> Ben Brugman
1. At Source Use BCP OUT to text file with Delimiter , Zip ( If file
is huge) , Upload through FTP At Destination FTP Download, UnZIP, BCP
IN (or BULK INSERT)
2. use SSIS or DTS