Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

Friday, March 30, 2012

i had a problem in inserting data in a table with foriegn key

i hav following 2 tables n i am able to insert data into the second table having a foriegn key

create table Customer_Details(
Customer_ID integer primary key,
Customer_First_Name varchar(75),
Customer_Last_Name varchar(75),
Address varchar(100))

create table Account_Details(
Account_No integer primary key,
Customer_ID integer foreign key references
Customer_Details(Customer_ID),
Debit float,Credit float,Balance float )hi
can u please put ur insert and also when a column is PK it cant be null. when u do not put any think then that means it also can be a null value but pk can't be null at all.

I get this error "Protocol error in TDS Stream".

Hi
I have a table with following structure
Field1 VarChar(10)
Field2 VarChar(10)
Field3 Text
In this table there are 3000 records and for each record the Field3 contains
around 50000 to 60000 characters.
In SQL Query Analyzer, If I select all the records in the above table, I get
this error "Protocol error in TDS Stream". Can any one help me out to
resolve this error ?
Thanks,
SubbuThis is generally a bug in either SQL Server or the SQL Server ODBC Driver.
You should contact Product Support to report the problem.
Brannon Jones
Developer - MDAC
This posting is provided "as is" with no warranties and confers no rights.
"Subbu" <subbu@.chellasoft.nospam.com> wrote in message
news:OpAANsYwDHA.3496@.TK2MSFTNGP11.phx.gbl...
quote:

> Hi
> I have a table with following structure
> Field1 VarChar(10)
> Field2 VarChar(10)
> Field3 Text
> In this table there are 3000 records and for each record the Field3

contains
quote:

> around 50000 to 60000 characters.
> In SQL Query Analyzer, If I select all the records in the above table, I

get
quote:

> this error "Protocol error in TDS Stream". Can any one help me out to
> resolve this error ?
> Thanks,
> Subbu
>

I found a bug in Sql Server 2000!!!

Yesterday I created a table in Sql Server 2000,using this script:
CREATE TABLE [dbo].[User](
[Id] [int] NOT NULL,
[UserName] [nvarchar](20) NOT NULL,
[TrueName] [nvarchar](20) NOT NULL,
[Password] [nvarchar](60) NOT NULL,
[Department] [int] NOT NULL,
[Mobile] [nvarchar](20) NULL,
[Telephone] [nvarchar](20) NULL,
[Remark] [nvarchar](200) NULL,
[Enabled] [bit] NOT NULL,
[Available] [bit] NOT NULL,
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED
(
[Id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
There was only one record in it:
INSERT INTO [User] VALUES(1,N'SUP',N'Jim',N'213123',1,NULL,NULL,NULL,1,1)
After I executed this script:UPDATE [User] SET UserName=N'f',TrueName=N'gg',[Password]=N'dfsdfsdf',Mobile=NULL,Telephone=NULL,Remark=NULL,
Enabled=1 WHERE [Id]=1 AND Available=1
The value of 'Available' field changed to Zero.That was not supposed to happen.
I'm pretty sure it is a bug, because when I did the same thing in Sql Server 2005, everything was correct.
Anybody can tell me if this is a known bug? I searched google,but couldn't find any answer.
Thanks!
"The value of 'Available' field changed to Zero"
Nope. Does not happened when i try it on my SQL Server 2000. It is still 1.
|||Thank you for trying it. But it went wrong on my machine. I also tried

in several other machines(all had service pack4 installed). They all

changed the 'Available' field.

Weirdly enough, when I changed the table structure, for example ,

changing the nvarchar field to nchar or cutting away the 'Enabled'

field, the bug disappeared.

Can anybody else try it? Please|||

Hi Okay,

No issues running on a 2k sp4 machine here.

Cheers

Rob

|||

Robert Varga wrote:

Hi Okay,

No issues running on a 2k sp4 machine here.

Cheers

Rob


Not win2000 sp4. I meant Sql Server 2000 sp4. The system is XP sp2.|||

Yes, that's what I meant: 2k = 2000, sp4

|||Mine is Personal Edition.I tried on Developer Edition just now, it didn't happen. Maybe that's the reason.

I don't want user dynamic sql

Dear all,
I have a stored procedure which might do INSERT, UPDATE over a specified
table.
Issue is that, at the outset, that table is totally unknown:
' into aux_PLAZO_PRIMER_IMPAGO ' +
' from ' + @.TABLA_COB
EXEC
..
' end DISC043 ' +
' into aux_PLAZO_PRIMER_IMPAGO ' +
' from ' + @.TABLA_COB
EXEC...
BLA,BLA,
I'm looking for a best version of that, dangerous dynamic sql is not well
welcomed here so that...
Declaring a variable as table also to solve the problem.
Thanks in advance for any input,
--
Please post DDL, DCL and DML statements as well as any error message in
order to understand better your request. It''s hard to provide information
without seeing the code. location: Alicante (ES)Enric
The best solution is know a table name that you operate on.
http://www.sommarskog.se/dynamic_sql.html
"Enric" <vtam13@.terra.es.(donotspam)> wrote in message
news:72F7C1B3-7C25-414A-8957-D9B0472476D6@.microsoft.com...
> Dear all,
> I have a stored procedure which might do INSERT, UPDATE over a specified
> table.
> Issue is that, at the outset, that table is totally unknown:
> ' into aux_PLAZO_PRIMER_IMPAGO ' +
> ' from ' + @.TABLA_COB
> EXEC
> ..
> ' end DISC043 ' +
> ' into aux_PLAZO_PRIMER_IMPAGO ' +
> ' from ' + @.TABLA_COB
> EXEC...
> BLA,BLA,
> I'm looking for a best version of that, dangerous dynamic sql is not well
> welcomed here so that...
> Declaring a variable as table also to solve the problem.
> Thanks in advance for any input,
> --
> Please post DDL, DCL and DML statements as well as any error message in
> order to understand better your request. It''s hard to provide information
> without seeing the code. location: Alicante (ES)|||not sure if this is what you're looking for, but sp_executesql is the
first step to prevent SQL injection attacks. after that you're next
best step would be to validate the table against the sysobjects table
to ensure that it is a real table.|||I'm not sure I agree with what he says on that link. IMO he uses exec
way too much. His reasons for not using sp_executesql do not make
sense, and while he does suggest using quotename(), stored procedures
are a better way to ensure that your parameters are unable to be
anything other than the datatype suggested.|||Create as many INSERT and UPDATE procedures as there are tables, that's the
best advice any one can (and should) give you.
If you don't care about data, however, you could just as well store it all
in a single table. (NOT RECOMMENDED!)
I see no reason for dynamic SQL in such elementary processes as inserting,
updating or deleteing a row in a table - building the query string might eve
n
take longer than the execution (i.e. if you decide to do it right - clean up
the parameters to prevent SQL injection, check whether objects exist,
validating the parameters that contain actual values, etc.).
ML
http://milambda.blogspot.com/|||I don't know if this is the situation, but creating a generic insert /
update procedure for tables that store different types of objects is a bad
idea. Even if it's not the case now, as time goes on, there will be a need
to implment additional table specific parameters, data validation
programming, etc. and the procedure will become a big pile of unmanageable
spaghetti. Business rules for things like data validation and referential
integrity are best embedded at the table level in the form of constraints
and triggers.
Generic data access programming is best implmented on the application side
in the form of a data access class.
Designing Data Tier Components and Passing Data Through Tiers:
http://msdn.microsoft.com/library/d...Gag
.asp
On the other hand, if these tables store the same object (vertical
paritioning), then you can implement a partitioned view and perform inserts
/ updates into that:
Modifying Data in Partitioned Views:
http://msdn2.microsoft.com/en-us/library/ms187067.aspx
Strategies for Partitioning Relational Data Warehouses in Microsoft SQL
Server:
http://www.microsoft.com/technet/pr.../2005/spdw.mspx
That said; if dynamic SQL can't be avoided, here my links on the topic of
SQL injection:
http://www.sqlservercentral.com/col...qlinjection.asp
http://www.sqlservercentral.com/col...ectionpart1.asp
http://www.nextgenss.com/papers/adv...l_injection.pdf
"Enric" <vtam13@.terra.es.(donotspam)> wrote in message
news:72F7C1B3-7C25-414A-8957-D9B0472476D6@.microsoft.com...
> Dear all,
> I have a stored procedure which might do INSERT, UPDATE over a specified
> table.
> Issue is that, at the outset, that table is totally unknown:
> ' into aux_PLAZO_PRIMER_IMPAGO ' +
> ' from ' + @.TABLA_COB
> EXEC
> ..
> ' end DISC043 ' +
> ' into aux_PLAZO_PRIMER_IMPAGO ' +
> ' from ' + @.TABLA_COB
> EXEC...
> BLA,BLA,
> I'm looking for a best version of that, dangerous dynamic sql is not well
> welcomed here so that...
> Declaring a variable as table also to solve the problem.
> Thanks in advance for any input,
> --
> Please post DDL, DCL and DML statements as well as any error message in
> order to understand better your request. It''s hard to provide information
> without seeing the code. location: Alicante (ES)|||Will (william_pegg@.yahoo.co.uk) writes:
> I'm not sure I agree with what he says on that link. IMO he uses exec
> way too much. His reasons for not using sp_executesql do not make
> sense, and while he does suggest using quotename(), stored procedures
> are a better way to ensure that your parameters are unable to be
> anything other than the datatype suggested.
What I try to say about this particular case, is that that you should
not do this at all. That is, you should have one procedure per table.
I can't recall that I suggest that EXEC() should be used over sp_executesql,
but you are right that the text could be stronger on using sp_executesql,
and most of all using parameters. In fact, I'm already working with
reworking the article with a lot more emphasis on sp_executesql.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

I don't want my cube to sort my measures and dimensions alphabetically

My cube has multiple measures and dimensions, and I want them to show in the field list of my pivot table in a specific order. However, when I preview them in BI Development Studio Browser, it automatically sorts in alphabetical. I don't want Analysis Service to reorder my measures and dimensions. Is there a way to diable the sorting feature of SSAS?

I'm afraid it's not possible:(. Oledb specification explicitly states that measure schema rowset (same true for dimensions) are sorted by name.

http://msdn2.microsoft.com/es-es/library/ms126250.aspx

You can try (and I have not tries this approach myself) to name dimensions and measures so, the form a specific order and give captions that are what you want your user to see. The more I think about this approach the less I like it.

Wednesday, March 28, 2012

I don't understand this "server timeout"

I was doing update statements in SQL Server 2000.

I have a table with over 16 million rows.

It came from several hundred delimited text files,
and two of the columns are file ID (int) and Line # (int)

Structure is X12 (835). For those unfamiliar with that,
each file has one to many BPR lines; each BPR line has
zero to many CLP lines, each of those has zero to many
SVC lines, each of those has zero to many CAS lines.

Working with this through the Enterprise Manager MMC,
a lot of things I tried got timeouts.

So, I indexed File ID, Line number, and line type, and
created a new table containing only the columns I knew
I would need in the final output--selected fields from
some of the line types mentioned, plus the line numbers
and common file ID for those rows.

I indexed every column in that table that I thought I might
search on.

I loaded it with 31 thousand rows using a select on a
subset of the CAS rows. That took far less than a minute.

I updated each row with the highest BPR line number not higher
than the CASE line number. About a minute. Not bad, with having
the worst case number of comparisons being 16 million times 31 thousand.
Of course, the indexing should help plus it can be narrowed down by
the "same file" and BPR # < CAS # criteria.

But the next update should theoretically be faster: each row now has
a BPR # and a CAS # and I am telling it to find the highest CLP number
BETWEEN those two. So it should have a MUCH smaller set of to search
through. Yet it thinks for about five minutes and then announces a timeout.

Any suggestions?

--
Wes Groleau

Measure with a micrometer, mark with chalk, and cut with an axe.Wes Groleau (groleau+news@.freeshell.org) writes:

Quote:

Originally Posted by

Working with this through the Enterprise Manager MMC,
a lot of things I tried got timeouts.
>
So, I indexed File ID, Line number, and line type, and
created a new table containing only the columns I knew
I would need in the final output--selected fields from
some of the line types mentioned, plus the line numbers
and common file ID for those rows.
>
I indexed every column in that table that I thought I might
search on.
>
I loaded it with 31 thousand rows using a select on a
subset of the CAS rows. That took far less than a minute.
>
I updated each row with the highest BPR line number not higher
than the CASE line number. About a minute. Not bad, with having
the worst case number of comparisons being 16 million times 31 thousand.
Of course, the indexing should help plus it can be narrowed down by
the "same file" and BPR # < CAS # criteria.
>
But the next update should theoretically be faster: each row now has a
BPR # and a CAS # and I am telling it to find the highest CLP number
BETWEEN those two. So it should have a MUCH smaller set of to search
through. Yet it thinks for about five minutes and then announces a
timeout.


Unforunately there is very little here to work from. X12 tells me
nothing. And in any case you have added a number of indexes that are
unknown to me. But let me point out thing: indexing single columns is
far from always sufficient. Often you need composite indexes.

To be able to say something more useful, I would be able to see
the CREATE TABLE statements for the tables. (Or is there only one?),
as well as the indexes, including keys. And of course I would need
to know your UPDATE statements. And if there are any triggers, I
need to see those as well.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland Sommarskog wrote:

Quote:

Originally Posted by

Unforunately there is very little here to work from. X12 tells me
nothing. And in any case you have added a number of indexes that are
unknown to me. But let me point out thing: indexing single columns is
far from always sufficient. Often you need composite indexes.
>
To be able to say something more useful, I would be able to see
the CREATE TABLE statements for the tables. (Or is there only one?),
as well as the indexes, including keys. And of course I would need
to know your UPDATE statements. And if there are any triggers, I
need to see those as well.


No triggers. I tried to script the table (actually I tried to script
a similar table to save myself some typing) but the wizard saved no file
and gave no error message. So I copied the table and used the GUI to
strip out the fields I didn't need/add a few others

All the fields referenced in the UPDATE statements are indexed.

The update statements are almost identical--the difference is that in

UPDATE Output SET xyz = (SELECT Max(Seg_Nbr) FROM Raw_Segs
WHERE Output.FID = Raw_Segs AND Seg_Nbr BETWEEN abc and pqr)

xyz, abc, & pqr are different columns, such that pqr - abc is
a wider range in the one that works; narrower in the one that
dies with timeout.

--
Wes Groleau

A pessimist says the glass is half empty.

An optimist says the glass is half full.

An engineer says somebody made the glass
twice as big as it needed to be.|||Erland Sommarskog wrote:

Quote:

Originally Posted by

To be able to say something more useful, I would be able to see
the CREATE TABLE statements for the tables. (Or is there only one?),
as well as the indexes, including keys. And of course I would need
to know your UPDATE statements. And if there are any triggers, I
need to see those as well.


Sorry for the too-soon send.

As I said, I did the table design with the GUI but it would be equivalent to
( CAS_Seg int,
SVC_Seg int,
CLP_Seg int,
BPR_Seg int,
other fields )

CAS_Seg is loaded first, with an INSERT from a view of Raw_Segs.

Then BPR_Seg is updated with the highest Seg_Nbr lass than CAS_Seg in
the same file. Works.

Then one of the updates I just sent is tried and times out.

--
Wes Groleau
--
"The reason most women would rather have beauty than brains is
they know that most men can see better than they can think."
-- James Dobson|||Wes Groleau (groleau+news@.freeshell.org) writes:

Quote:

Originally Posted by

No triggers. I tried to script the table (actually I tried to script
a similar table to save myself some typing) but the wizard saved no file
and gave no error message. So I copied the table and used the GUI to
strip out the fields I didn't need/add a few others
>
All the fields referenced in the UPDATE statements are indexed.
>
The update statements are almost identical--the difference is that in
>
UPDATE Output SET xyz = (SELECT Max(Seg_Nbr) FROM Raw_Segs
WHERE Output.FID = Raw_Segs AND Seg_Nbr BETWEEN abc and pqr)
>
xyz, abc, & pqr are different columns, such that pqr - abc is
a wider range in the one that works; narrower in the one that
dies with timeout.


Again, CREATE TABLE and CREATE INDEX statements for your two tables
would help. Knowing that "all fields ... are indexed" is not a very
useful piece of information. I would need to know where in the index
the column appears, and which index that is the clustered index, if
there is any.

But you could try:

UPDATE Output
SET xyz = R.maxseg
FROM Output o
JOIN (SELECT Raw_segs, maxseg = Max(Seg_Nbr)
FROM Raw_Segs
WHERE Seg_Nbr BETWEEN abc AND pqr) R
ON Output.FID = R.Raw_Segs

While this syntax is proprietary and not portable, it often yields better
results than a correlated subquery.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland Sommarskog wrote:

Quote:

Originally Posted by

But you could try:
>
UPDATE Output
SET xyz = R.maxseg
FROM Output o
JOIN (SELECT Raw_segs, maxseg = Max(Seg_Nbr)
FROM Raw_Segs
WHERE Seg_Nbr BETWEEN abc AND pqr) R
ON Output.FID = R.Raw_Segs
>
While this syntax is proprietary and not portable, it often yields better
results than a correlated subquery.


I think I also tried that, but maybe not. I'm going in to work today,
so I'll make sure. And I'll make another try at extracting a script
from that thing.

--
Wes Groleau

Expert, n.:
Someone who comes from out of town and shows slides.|||Wes Groleau (groleau+news@.freeshell.org) writes:

Quote:

Originally Posted by

I think I also tried that, but maybe not. I'm going in to work today,
so I'll make sure. And I'll make another try at extracting a script
from that thing.


Note that you can also script from Query Analyzer.

And if only the timeout bothers you, run the UPDATE from QA. QA does not
have any timeouts.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland Sommarskog wrote:

Quote:

Originally Posted by

But you could try:
>
UPDATE Output
SET xyz = R.maxseg
FROM Output o
JOIN (SELECT Raw_segs, maxseg = Max(Seg_Nbr)
FROM Raw_Segs
WHERE Seg_Nbr BETWEEN abc AND pqr) R
ON Output.FID = R.Raw_Segs
>
While this syntax is proprietary and not portable, it often yields better
results than a correlated subquery.


Or maybe

UPDATE Output
SET xyz = R.maxseg
FROM Output o
JOIN (SELECT FID, maxseg = Max(Seg_Nbr)
FROM Raw_Segs
WHERE Seg_Nbr BETWEEN abc AND pqr) R
ON Output.FID = R.FID

But unfortunately, Ent. Mgr/SQL Svr 2000 rejected this, saying that the
optional FROM syntax is not supported. By some experimentation, I got
THAT message to go away (even though both FROMs were still there).

But none of the ten variations I tried were accepted.
(By the way, page 72 and following of SQL Cookbook offers both this
approach and the one that my first approach was based on. But the
syntax it says will work for the first approach was also rejected
by my system--though I managed to alter it enough to work in the one case.

Apparently, the "optimizer" is not very smart. I eventually got the job
done as follows:

Load Raw_Segments

Create and insert Raw_BPR, Raw_CLP, Raw_SVC, Raw_CAS, Patient_Names, etc.

Index the above

Create Inv_Data with indexes

Crate view or table Selected_Adjustments from Raw_CAS

INSERT INTO Inv_Data
(FID, CAS_Seg, Adj_Group, Adj_Reason, Adj_Amount)
SELECT FID, Seg_Nbr, Type, Code, CAST(Amount AS money)
AS Expr1
FROM Selected_Adjustments

UPDATE Inv_Data
SET SVC_Seg = (SELECT MAX(Seg_Nbr)
FROM Raw_SVC AS Raw
WHERE Inv_Data.FID = Raw.FID
AND CAS_Seg Seg_Nbr)

UPDATE Inv_Data
SET Service = (SELECT Elem_01
FROM Raw_SVC AS Raw
WHERE Inv_Data.FID = Raw.FID
AND SVC_Seg Seg_Nbr)

UPDATE Inv_Data
SET CLP_Seg = (SELECT MAX(Seg_Nbr)
FROM Raw_CLP AS Raw
WHERE Inv_Data.FID = Raw.FID
AND CAS_Seg Seg_Nbr)

UPDATE Inv_Data
SET BPR_Seg = (SELECT MAX(Seg_Nbr)
FROM Raw_BPR AS Raw
WHERE Inv_Data.FID = Raw.FID
AND CAS_Seg Seg_Nbr)

Each update takes about ten seconds this way.

No doubt there's a simpler way, but I'm new at this.

--
Wes Groleau

He that complies against his will is of the same opinion still.
-- Samuel Butler, 1612-1680|||Erland Sommarskog wrote:

Quote:

Originally Posted by

And if only the timeout bothers you, run the UPDATE from QA. QA does not
have any timeouts.


How do you do that? When I click the icon that has the tooltip
"execution mode," it acts like it's doing something for a while,
and then it displays an execution plan. But the table is unchanged.

Then I select/copy the SQL, paste it into the Enterprise Manager and
click the exclamation point. It complains of a syntax error.

This happened before--I just forgot to mention it.

Removing the syntax error got the time out.

Maybe the timeout is because in one case (no timeout)
it first gathered part of the subquery (877 rows of 16 million)
making the second part 877 comparing to 31000. But if it
tries the other part first, it is checking the full 31000 rows
against the original 16 million.

I don't know whether that happened, but it would explain
why I did the job in less than sixty seconds by doing some
of the subqueries as separate extract and insert steps.

--
Wes Groleau
Heroes, Heritage, and History
http://freepages.genealogy.rootsweb.com/~wgroleau/|||Wes Groleau (groleau+news@.freeshell.org) writes:

Quote:

Originally Posted by

How do you do that? When I click the icon that has the tooltip
"execution mode,"


You click on the green arrow. (Or press F5 or CTRL/E.) Then it will
run the query which is the window.

I strongly encourage you to get acquianted with Query Analyzer to
run your queries. What you have in Enterprise Manager is a query
designer, and a fairly limited one as testified about the bogus message
about the FROM clause not being supported.

In Query Analyzer you are only limited by what SQL Server permits; the
tool itself does not limit you.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland Sommarskog wrote:

Quote:

Originally Posted by

Wes Groleau (groleau+news@.freeshell.org) writes:

Quote:

Originally Posted by

>How do you do that? When I click the icon that has the tooltip
>"execution mode,"


>
You click on the green arrow. (Or press F5 or CTRL/E.) Then it will
run the query which is the window.


Thanks. I don't recall what the icon was that I clicked,
only that it's tooltip said "execution mode" and that clicking it
caused around ten seconds of "hourglass" but no changes to the
table.

Quote:

Originally Posted by

I strongly encourage you to get acquianted with Query Analyzer to
run your queries. What you have in Enterprise Manager is a query
designer, and a fairly limited one as testified about the bogus message
about the FROM clause not being supported.


Noted. I guess I'd better do so--although I'd rather get
SQL Server 2005, since that's what I went to class for.

--
Wes Groleau
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^
^ A UNIX signature isn't a return address, it's the ASCII equivalent ^
^ of a black velvet clown painting. It's a rectangle of carets ^
^ surrounding a quote from a literary giant of weeniedom like ^
^ Heinlein or Dr. Who. ^
^ -- Chris Maeda ^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^|||Wes Groleau (groleau+news@.freeshell.org) writes:

Quote:

Originally Posted by

Quote:

Originally Posted by

>I strongly encourage you to get acquianted with Query Analyzer to
>run your queries. What you have in Enterprise Manager is a query
>designer, and a fairly limited one as testified about the bogus message
>about the FROM clause not being supported.


>
Noted. I guess I'd better do so--although I'd rather get
SQL Server 2005, since that's what I went to class for.


In SQL 2005, Enterprise Manager and Query Analyzer are both replaced
with SQL Server Management Studio. The Query Designer is still there,
and is still very limited, and you still do best to avoid it. Running
queries from the Query Editor is the way to go.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland Sommarskog wrote:

Quote:

Originally Posted by

In SQL 2005, Enterprise Manager and Query Analyzer are both replaced
with SQL Server Management Studio. The Query Designer is still there,
and is still very limited, and you still do best to avoid it. Running
queries from the Query Editor is the way to go.


Thanks for the tip. I'm saving it in case they ever actually
give us 2005.

We also have Oracle, but I don't have access to it.

--
Wes Groleau
Alive and Well
http://freepages.religions.rootsweb.com/~wgroleau/|||I STILL don't understand the server timeout.

Erland Sommarskog wrote:

Quote:

Originally Posted by

And if only the timeout bothers you, run the UPDATE from QA. QA does not
have any timeouts.


Surprise! I went back to QA with your JOIN method. It would not accept
it, nor various modifications of it.

I ended up using more UPDATE queries similar to the ones I posted
before. The last two are particularly interesting. Each updated three
columns in Inv_Data. Each had the exact same structure except for the
WHERE clause. One came from table X, one from table Y (I forget the
exact names, but they don't matter).

ALL referenced columns in X and Y and Inv_Data are indexed in the same
manner (not clustered) except for the three fields being changed.

X and Y have the same number of rows and the fields used to select are
the same type and name. (And they have a small fraction of the number
of rows that did not cause a timeout in an earlier similar update)

The query that ended WHERE X.Seg_Nbr Inv_Data.CAS_Seg completed
in under ten seconds.

The one that ended
WHERE X.Seg_Nbr BETWEEN Inv_Data.CLP_Seg AND Inv_Data.CAS_Seg
got a timeout from the server after about a minute.
(So perhaps QA doesn't timeout, but the server still does!)

The "estimated execution plans" were the same.

Changing the BETWEEN to the equivalent < CAS and CLP didn't help.

Exiting QA and EM, defragmenting the drive, logging out and back in
and opening only QA -- didn't help.

I am now trying to do the work one input file at a time and then
insert the end result in the desired output. This way X and Y will
have 800-1500 rows instead of over 400K (but 16 MILLION did not get
a timeout!)

Curiouser and curiouser...

--
Wes Groleau
Heroes, Heritage, and History
http://freepages.genealogy.rootsweb.com/~wgroleau/|||Wes Groleau (groleau+news@.freeshell.org) writes:

Quote:

Originally Posted by

Erland Sommarskog wrote:

Quote:

Originally Posted by

>And if only the timeout bothers you, run the UPDATE from QA. QA does not
>have any timeouts.


>
Surprise! I went back to QA with your JOIN method. It would not accept
it, nor various modifications of it.


Well, since you never care about posting your table defitions or sample
data, do you really expect me to post a tested working query? Maybe you
could at least post the actual query you tried, and the error message?

I am sorry if my tone is somewhat irritated, but it is very difficult
to assist when the person asking for help refuse to dislose vital
information.

Quote:

Originally Posted by

The one that ended
WHERE X.Seg_Nbr BETWEEN Inv_Data.CLP_Seg AND Inv_Data.CAS_Seg
got a timeout from the server after about a minute.
(So perhaps QA doesn't timeout, but the server still does!)


Again, can you post the actual error message, and the exact query you are
using? If you get a timeout, it may be that you are using a linked server.
(Not that you ever said that you are using linked server, but at this
point I'm starting to feel like a participant in a quiz competition.)

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland Sommarskog wrote:

Quote:

Originally Posted by

Again, can you post the actual error message, and the exact query you are
using? If you get a timeout, it may be that you are using a linked server.


Not sure what is meant by "linked" but when I start QA,
I leave the server choice on "(local)"

I will see whether I can capture some of this information.

--
Wes Groleau

Answer not a fool according to his folly,
lest thou also be like unto him.
Answer a fool according to his folly,
lest he be wise according to his own conceit.
-- Solomon

Are you saying there's no good way to answer a fool?
-- Groleau|||Erland Sommarskog wrote:

Quote:

Originally Posted by

Well, since you never care about posting your table defitions or sample
data, do you really expect me to post a tested working query? Maybe you
could at least post the actual query you tried, and the error message?


I'm not trying to be obscure--it's just that (1) I don't have access
to that system and Usenet at the same time and place and (2) the table
definitions were done with the GUI and (3) I couldn't get the scripting
to work. (I've done it before, but this time it asks for a filename and
then doesn't create the file)

Quote:

Originally Posted by

Again, can you post the actual error message, and the exact query you are


Here is what I thought I had already posted, but I have added more
explanation to it since then:
Load Raw_Segments

Raw_Segments
( FID int,
Seg_Nbr int,
SegType varchar(5),
Elem_01 varchar(x),
Elem_02 varchar(y), x, y, ..., z are between 10 and 50
...
Elem_nn varchar(z) )

FID, Seg_Nbr, SegType are in the same nonclustered index

Raw_Segments was loaded from one humongous file by DTS.

Create and insert Raw_BPR, Raw_CLP, Raw_SVC, Raw_CAS, Patient_Names, etc.

I forget how I created these but each has the same structure/definition
as Raw_Segments but a subset of the data. BPR, CLP, SVC, CAS are
SegTypes and Patient_Names is all the segments where SegType = 'NM1'
and Elem_01 =s 'QC'

Index the above the same as Raw_Segments

Create Inv_Data with indexes

From memory, probably
Inv_Data
( FID int, -- A
CAS_Seg int, -- B
Adj_Group varchar, -- C
Adj_Reason varchar, -- D
Adj_Amount money, -- E
SVC_Seg int, -- F
Service varchar, -- G
Name varchar, -- H
CLP_Seg int, -- I
Claim varchar, -- J
Status varchar, -- K
Charges money, -- L
BPR_Seg int, -- M
RA_Date date, -- N
Check_Amount money, -- O
Provider varchar ) -- P

A,B,D,F,H,I,J,M,P are indexed

Create View Selected_Adjustments from Raw_CAS

INSERT INTO Raw_CAS SELECT * FROM Raw_Segments WHERE SegType = 'CAS'

A CAS Segment can have up to six adjustments in different columns in the
same row so Selected_Adjustments is a view giving the union of
six selects to map them all into one set per row. Plus each has a
filter of Code in ('22', 'B22', '12', '50')

Raw_? is like Raw_CAS

INSERT INTO Inv_Data -- which is empty until this happens
(FID, CAS_Seg, Adj_Group, Adj_Reason, Adj_Amount)
SELECT FID, Seg_Nbr, Type, Code, CAST(Amount AS money)
AS Expr1
FROM Selected_Adjustments -- this worked

-- Of the following updates, some worked and some timed out:
UPDATE Inv_Data
SET SVC_Seg = (SELECT MAX(Seg_Nbr)
FROM Raw_SVC AS Raw
WHERE Inv_Data.FID = Raw.FID
AND Inv_Data.CAS_Seg Raw.Seg_Nbr)

UPDATE Inv_Data
SET Service = (SELECT Elem_01
FROM Raw_SVC AS Raw
WHERE Inv_Data.FID = Raw.FID
AND SVC_Seg = Seg_Nbr)

DELETE
FROM Inv_Data AS I
WHERE Adj_Reason = '50'
AND Service not like '%GA%'

UPDATE Inv_Data
SET CLP_Seg = (SELECT MAX(Seg_Nbr)
FROM Raw_CLP AS Raw
WHERE Inv_Data.FID = Raw.FID
AND CAS_Seg Seg_Nbr)

UPDATE Inv_Data
SET BPR_Seg = (SELECT MAX(Seg_Nbr)
FROM Raw_BPR AS Raw
WHERE Inv_Data.FID = Raw.FID
AND CAS_Seg Seg_Nbr)

UPDATE Inv_Data
SET (fill in all the missing fields from Raw_whatever)

--
Wes Groleau

Change is inevitable. We need to learn that "inevitable" is
neither a synonym for "good" nor for "bad."
-- WWG|||Wes Groleau (groleau+news@.freeshell.org) writes:

Quote:

Originally Posted by

I'm not trying to be obscure--it's just that (1) I don't have access
to that system and Usenet at the same time and place and (2) the table
definitions were done with the GUI and (3) I couldn't get the scripting
to work. (I've done it before, but this time it asks for a filename and
then doesn't create the file)


As I've said you can script from Query Analyzer as well.

And I am sorry, but I don't feel inclined to come with further
guesses without the error messages you are getting. Nor am I interested
in composing queries and then only hear "it wouldn't take them". I
understand that it may be difficult for you to bring the information
from one corner to another, but it is even more difficult for me
who don't even see the queries. And after all, copying an error message
from one corner of a room to another is not rocket science. Pen and
paper still works...

Quote:

Originally Posted by

>Not sure what is meant by "linked" but when I start QA,
>I leave the server choice on "(local)"


A linked server is a remote data source, which is accessed from SQL
Server in a distributed query. The linked server can be another SQL
Server, but can also be an Access database, Oracle database, Active
directory or anything else for which there is an ODBC driver or OLE DB
provider.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland Sommarskog wrote:

Quote:

Originally Posted by

And I am sorry, but I don't feel inclined to come with further
guesses without the error messages you are getting. Nor am I interested
in composing queries and then only hear "it wouldn't take them". I


I understand. What you did offer is appreciated.

Quote:

Originally Posted by

A linked server is a remote data source, which is accessed from SQL
Server in a distributed query. The linked server can be another SQL
Server, but can also be an Access database, Oracle database, Active
directory or anything else for which there is an ODBC driver or OLE DB
provider.


OK, then (as I suspected) it is not a linked server.

--
Wes Groleau

Nobody believes a theoretical analysis -- except the guy who did it.
Everybody believes an experimental analysis -- except the guy who
did it.
-- Unknown|||Wes Groleau (groleau+news@.freeshell.org) writes:

Quote:

Originally Posted by

Erland Sommarskog wrote:

Quote:

Originally Posted by

>And I am sorry, but I don't feel inclined to come with further
>guesses without the error messages you are getting. Nor am I interested
>in composing queries and then only hear "it wouldn't take them". I


>
I understand. What you did offer is appreciated.


Permit me to make the final remark, that I'm only asking for error
messages and that for my own sake. If you want help with your problems,
there is no reason why you shouldn't make the effort to transfer the
information to the newsgroup.

But if you don't want to make that effort to get your issues resovled -
well that's your call.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland Sommarskog wrote:

Quote:

Originally Posted by

Permit me to make the final remark, that I'm only asking for error
messages and that for my own sake. If you want help with your problems,
there is no reason why you shouldn't make the effort to transfer the
information to the newsgroup.


Obviously no one here is obligated to help, so I can't complain
if I get even a crumb. I did not preserve any of the error messages,
as I am under pressure to show progress. I got the thing working
in Access with a subset of the files. But there is NO WAY Access
will handle the quantity of data that is in the full set of files.

So I will have to go back to SQL Server, and when that happens,
I will try to capture any error messages. If there are any.

Thanks for your kindness--and that of the few others who contributed.

--
Wes Groleau

Even if you do learn to speak correct English,
whom are you going to speak it to?
-- Clarence Darrow

I don't suppose BULK UPDATE exists?... like BULK INSERT?

I have to update a field within a table of 60 records or so. Each record has a different field value. it's type varchar. i was given an excel file with the field values and was thinking of a bulk update like bulk insert, but i don't recall that it's possible that way.

Is the only way to create a table, bulk insert, then merge the two tables together with UPDATE?

Just wanted to see if there was an easier way to do it, otherwise i'll take the latter route. Thanks!

You'll need to bulk insert into a work table, then do the update.

Unfortunately (or maybe, fortunately ) there's not Bulk Update.

Or, you could do the processing with SSIS....

I don't remember...

Dear folks,
Could you please so kind to tell me where the fixed type data stored are? I
mean, in what system table are available these data?
"bigint, binary, float, decimal", and so on
Thanks in advance and regards,
Enricsystypes
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Enric" <Enric@.discussions.microsoft.com> wrote in message
news:0FEAE3E6-C6D8-400E-B210-F999DEBE6D17@.microsoft.com...
> Dear folks,
> Could you please so kind to tell me where the fixed type data stored are?
I
> mean, in what system table are available these data?
> "bigint, binary, float, decimal", and so on
> Thanks in advance and regards,
> Enric|||thanx
"Tibor Karaszi" wrote:

> systypes
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Enric" <Enric@.discussions.microsoft.com> wrote in message
> news:0FEAE3E6-C6D8-400E-B210-F999DEBE6D17@.microsoft.com...
>
>

I didn't drop the table

Hi, Andrea,
Thank you for your reply.
I didn't drop the table,and the records in the table seldom change.
Does it has anything to do with the weekly backup schedule? I remember I
once did something wrong and I had to restore the database.
Thanks for any relpy.
Long
hi,
Long wrote:
> Hi, Andrea,
> Thank you for your reply.
> I didn't drop the table,and the records in the table seldom change.
> Does it has anything to do with the weekly backup schedule? I
> remember I once did something wrong and I had to restore the database.
> Thanks for any relpy.
> Long
if you modified your database and data, restoring an older (unmodified)
version can produce such problems
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.11.1 - DbaMgr ver 0.57.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply

I coulnt return a table from a procedure . Pls Help me

I couln't return a table from a procedure . Pls Help meCan you send the procedure ? Would help|||I didn't think (again?) you could...

I tried

USE Northwind
Go

CREATE PROC mySproc
@.Results TABLE ([name] sysname) OUTPUT
AS

INSERT INTO @.Results ([name]) SELECT [name] FROM sysobjects
GO

EXEC mySproc

And that didn't work...then I rea din BOL

E. Use an OUTPUT cursor parameter
OUTPUT cursor parameters are used to pass a cursor that is local to a stored procedure back to the calling batch, stored procedure, or trigger.

First, create the procedure that declares and then opens a cursor on the titles table:

USE pubs
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'titles_cursor' and type = 'P')
DROP PROCEDURE titles_cursor
GO
CREATE PROCEDURE titles_cursor @.titles_cursor CURSOR VARYING OUTPUT
AS
SET @.titles_cursor = CURSOR
FORWARD_ONLY STATIC FOR
SELECT *
FROM titles

OPEN @.titles_cursor
GO

Next, execute a batch that declares a local cursor variable, executes the procedure to assign the cursor to the local variable, and then fetches the rows from the cursor.

USE pubs
GO
DECLARE @.MyCursor CURSOR
EXEC titles_cursor @.titles_cursor = @.MyCursor OUTPUT
WHILE (@.@.FETCH_STATUS = 0)
BEGIN
FETCH NEXT FROM @.MyCursor
END
CLOSE @.MyCursor
DEALLOCATE @.MyCursor
GO

But why do you need to do this?|||My 2 cents ...

A Function can return a table variable but not a procedure. See if you can rewrite the SP as a UDF.

Originally posted by aneeshattingal
I couln't return a table from a procedure . Pls Help me|||Hey aneeshattingal,

Just a guess...but you have an Oracle background and are switching to sql server?

Monday, March 26, 2012

I can't see my Procedure. Why? This is my first Stored Procedure.

Hello,
I created the "MyDb" database using Microsoft SQL 2005 Server Management
Studio and I added the table "dbo.Surveys".
Then I right clicked on Store Procedures and created a new procedure.
When I close it I am asked to save it. I save it and gave the file a
name.
However my stored procedure doesn't show in the Stored Procedures list.
I can only access it by loading the file (File > Open > File). Why?
When I open the File the Connect Window shows again.
I believe the procedure is created because I used CREATE.
When I execute it twice I got the message that there is already another
procedure with that name so I change CREATE to ALTER.
Could you explain to me how to make my procedure visible in:
Databases/MyDb/Programmability/StoredProcedores
How to run it with dbo.Surveys table and see all the records that
returns?
Thank You,
Miguel
My Stored Procedure code is:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE dbo.Surveys_GetSurveyBySurveyName
-- Procedure Parameters
@.SurveyName nvarchar
AS
BEGIN
-- Prevent extra result sets from interfering with SELECT statements
SET NOCOUNT ON;
-- Procedure statements
SELECT m.SurveyName
FROM dbo.application_Surveys
WHERE @.SurveyName = u.SurveyName
IF ( @.@.ROWCOUNT = 0 ) -- Survey Name not found
RETURN -1
RETURN 0
END
GO> When I close it I am asked to save it. I save it and gave the file a name.
That is a file.

> However my stored procedure doesn't show in the Stored Procedures list.
> I can only access it by loading the file (File > Open > File). Why?
You need to *RUN* the CREATE PROCEDURE script to apply the procedure to the
database. This has nothing to do with a file you save on your hard drive.

> I believe the procedure is created because I used CREATE.
> When I execute it twice I got the message that there is already another
> procedure with that name so I change CREATE to ALTER.
Then maybe you created it in the wrong database? Just because you created a
database does not necessarily mean that your current query window is in that
database's context.

> Could you explain to me how to make my procedure visible in:
> Databases/MyDb/Programmability/StoredProcedores
Did you right-click and hit refresh? Did you try EXEC
dbo.Surveys_GetSurveyBySurveyName?

> My Stored Procedure code is:
What happens when you insert this here:

> SET ANSI_NULLS ON
> GO
> SET QUOTED_IDENTIFIER ON
> GO
USE MyDB
GO

> ALTER PROCEDURE dbo.Surveys_GetSurveyBySurveyName
...|||Well, have you hit F5 after creation the SP? Have you refresh on stored
procedure--system stored procedure folder?
"Miguel Dias Moura" <md*REMOVE*moura@.gmail*NOSPAM*.com> wrote in message
news:u$nJopbTGHA.5108@.TK2MSFTNGP09.phx.gbl...
> Hello,
> I created the "MyDb" database using Microsoft SQL 2005 Server Management
> Studio and I added the table "dbo.Surveys".
> Then I right clicked on Store Procedures and created a new procedure.
> When I close it I am asked to save it. I save it and gave the file a name.
> However my stored procedure doesn't show in the Stored Procedures list.
> I can only access it by loading the file (File > Open > File). Why?
> When I open the File the Connect Window shows again.
> I believe the procedure is created because I used CREATE.
> When I execute it twice I got the message that there is already another
> procedure with that name so I change CREATE to ALTER.
> Could you explain to me how to make my procedure visible in:
> Databases/MyDb/Programmability/StoredProcedores
> How to run it with dbo.Surveys table and see all the records that returns?
> Thank You,
> Miguel
> My Stored Procedure code is:
> SET ANSI_NULLS ON
> GO
> SET QUOTED_IDENTIFIER ON
> GO
> ALTER PROCEDURE dbo.Surveys_GetSurveyBySurveyName
> -- Procedure Parameters
> @.SurveyName nvarchar
> AS
> BEGIN
> -- Prevent extra result sets from interfering with SELECT statements
> SET NOCOUNT ON;
> -- Procedure statements
> SELECT m.SurveyName
> FROM dbo.application_Surveys
> WHERE @.SurveyName = u.SurveyName
> IF ( @.@.ROWCOUNT = 0 ) -- Survey Name not found
> RETURN -1
> RETURN 0
> END
> GO
>

I cant see my Procedure. Why? This is my first Stored Procedure.

Hello,

I created the "MyDb" database using Microsoft SQL 2005 Server Management Studio and I added the table "dbo.Surveys".

Then I right clicked on Store Procedures and created a new procedure.
When I close it I am asked to save it. I save it and gave the file a name.
However my stored procedure doesn't show in the Stored Procedures list.
I can only access it by loading the file (File > Open > File). Why?

When I open the File the Connect Window shows again.

I believe the procedure is created because I used CREATE.
When I execute it twice I got the message that there is already another procedure with that name so I change CREATE to ALTER.

Could you explain to me how to make my procedure visible in:
Databases/MyDb/Programmability/StoredProcedores

How to run it with dbo.Surveys table and see all the records that returns?

Thank You,
Miguel

My Stored Procedure code is:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE dbo.Surveys_GetSurveyBySurveyName
-- Procedure Parameters
@.SurveyName nvarchar
AS
BEGIN
-- Prevent extra result sets from interfering with SELECT statements
SET NOCOUNT ON;

-- Procedure statements
SELECT m.SurveyName
FROM dbo.application_Surveys
WHERE @.SurveyName = u.SurveyName

IF ( @.@.ROWCOUNT = 0 ) -- Survey Name not found
RETURN -1
RETURN 0

END
GO

USE MyDb

GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE dbo.Surveys_GetSurveyBySurveyName
-- Procedure Parameters
@.SurveyName nvarchar
AS
BEGIN
-- Prevent extra result sets from interfering with SELECT statements
SET NOCOUNT ON;

-- Procedure statements
SELECT m.SurveyName
FROM dbo.application_Surveys
WHERE @.SurveyName = u.SurveyName

IF ( @.@.ROWCOUNT = 0 ) -- Survey Name not found
RETURN -1
RETURN 0

END
GO

this one can create on sp on my machine.

Limno

|||

You must have created the stored proc in some other database.

Here's a script from SQLServerCentral.com that you can use to find any object: Compile the script in master database and exec it with the stored proc name.

/*
Purpose- Search object across database server.
Author-Vidyadhar P.
Email-vidya_pande@.yahoo.com
Date-6th-Feb-2006
Location- Pune,India
Input Parameters
@.object_name= Name of object to be searched part of object nameto be searched
@.ExactORLikeSearch= If no parameters are passed Sp will search for exact object names.
if 'L' is passes as parameter it will to like seach.
*/

create procedure dbo.sp_find_object -- 'product_master','L'
@.object_name varchar(100),
@.ExactORLikeSearch char(1)=E --E/L
as
begin
set nocount on
declare @.databases table (colid int identity ,dbname varchar(50))
create table ##object_db (dbName varchar(100), objectName varchar(100),objectType varchar(100))
insert into @.databases (dbname) select name from sysdatabases where dbid>4 and name not in ('pubs','northwind', 'holding_tank')
declare @.max_dbs int
select @.max_dbs=max(colid) from @.databases
declare @.current_db varchar(100)

declare @.Qstr nvarchar(2000)
declare @.Qstr1 nvarchar(2000)
set @.Qstr='insert into ##object_db select '
set @.Qstr1=''

declare @.i int
set @.i=1

while @.i<=@.max_dbs
begin
select @.current_db=dbname from @.databases wherecolid=@.i
--------------------------
if @.ExactORLikeSearch='E'

set @.Qstr1=@.Qstr+''''+@.current_db+''''+',name, case xtype when '+''''+'U'+'''' +' then ' +''''+'table'+''''+' when ' +''''+'P'+''''+' then '+''''+'procedure'+''''+' when '+''''+'F'+''''+' then '+''''+'function'+''''+' when '+''''+'V'+''''+' then '+''''+'view'+''''+ ' end as ObjectType
from '+@.current_db+'.dbo.sysobjects wherename='+''''+@.object_name+''''
--------------------------
if @.ExactORLikeSearch='L'

set @.Qstr1=@.Qstr+''''+@.current_db+''''+',name, case xtype when '+''''+'U'+'''' +' then ' +''''+'table'+''''+' when ' +''''+'P'+''''+' then '+''''+'procedure'+''''+' when '+''''+'F'+''''+' then '+''''+'function'+''''+' when '+''''+'V'+''''+' then '+''''+'view'+''''+ ' end as ObjectType
from '+@.current_db+'.dbo.sysobjects where namelike'+''''+'%'+@.object_name+'%'+'''' +'and xtype in ('+''''+'U'+''''+','+''''+'P'+''''+','+''''+'F'+','+''''+''''+'V'+''''+')'
--------------------------

exec sp_executesql @.Qstr1
set @.i=@.i+1
end

select * from ##object_db
drop table ##object_db

end

sql

Friday, March 23, 2012

I cant get current default value from DataTableReader, How can I do ?

I would like to check current structure especially "default value"

However

after I use DataTableReader to get structural value from any table

, there was only null value

How can I get structural value from real table in database with others method ??

Please help me ?

Hi,

I'm not clear what you want. But if you want to navigate the contents of a DataTableReader ,try the following articles.

http://msdn2.microsoft.com/en-us/library/z071789y(VS.80).aspx

Thanks.

sql

I cant figure out why this update isnt working

i dont know if it is just because im tired or what. im trying to do a update one this table here is the stored procedure im using

ALTER PROCEDURE Snake.UpdateSPlits @.name nvarchar(50),@.splitnvarchar(50)ASUpdate accountsSet split_id = @.splitWhere name = @.name RETURN
 
Here is what im using to call it
 
Protected Sub GridView1_RowUpdating(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.GridViewUpdateEventArgs)Handles GridView1.RowUpdatingMe.SqlDataSource1.UpdateParameters.Clear()Dim nameAs String =Me.GridView1.SelectedRow.Cells(0).TextDim SplitAs String =Me.GridView1.SelectedRow.Cells(1).TextDim pnameAs New Parameter("name", TypeCode.String, name)Me.SqlDataSource1.UpdateParameters.Add(pname)Dim psplitAs New Parameter("split", TypeCode.String, Split)Me.SqlDataSource1.UpdateParameters.Add(psplit)Me.SqlDataSource1.Update()End Sub
  
I keep getting one of 2 errors they are

Object reference not set to an instance of an object. or

one that says i had to many aurgements

any idea what im doing wrong?

 

Change these lines

Dim nameAs String =Me.GridView1.SelectedRow.Cells(0).TextDim SplitAs String =Me.GridView1.SelectedRow.Cells(1).Text

to

Dim nameAs String = e.NewValues["name"].ToString();Dim SplitAs String = e.NewValues["split"].ToString();

I guess above changes can solve your proble.

|||

In addition topooya.m's answer, try putting a break point and debug through your code.

|||

I tried that and getting this

Compiler Error Message:BC30203: Identifier expected.

Line 154:Me.SqlDataSource1.UpdateParameters.Clear()Line 155:Line 156:Dim nameAs String = e.NewValues["name"].ToString();Line 157:Dim SplitAs String = e.NewValues["split"].ToString();Line 158:

|||
Looks like u need to @.Name and @.split as the name of the parameters .. cause that whats ur sproc is expecting instead of Name and spilt
|||

YahoosSnake:

Line 156: Dim nameAs String = e.NewValues["name"].ToString();
Line 157: Dim SplitAs String = e.NewValues["split"].ToString();

You're getting the compiler error because the above code is not valid code. You are combining VB and C# style syntax. Use

Dim name As String = e.NewValues("name").ToString()
Dim Split As String = e.NewValues("split").ToString()

|||

DisturbedBuddha is right,

I used C# syntax to access NewValues. asDisturbedBuddha said you have to change NewValues["..."] to NewValues("...")

|||

How do i set up the web.confgire to run the debuger thorw vb.net 2005 i put this in the file already

<compilation debug="true" />

but i get this error

Unable to start debugging on the web server. Logon Fauilure, unknow username or bad password.

Where do i setup the username and password for my sever on the web.config file?

sql

I cant delete records

Hi,

My DB is MS SQL Server. I wrote a SQL statement to remove rows from a table as following.

DELETE FROM #TableA
FROM #TableA AS t1
LEFT JOIN #TableA AS t2 ON (t1.Index - 1) = t2.Index
WHERE t2.Index IS NULL

========================================

When I tried to execute it, I got the following error message.
Error Message: The table '#TableA' is ambiguous.

Thanks for your help.Interesting problem, never thought about it. I can imagine that MSSQL has some problem with guessing what to do.

I know it is not an answer to your question, the following syntax should do the same (if I got the query right) :

DELETE FROM #TableA
WHERE Index-1 NOT IN (SELECT Index FROM #TableA)

ps. Do you really have columns named "Index"|||You have answered my question.
Many Thanks.

I don't have a column named "Index", it is a alias to simply my question.

i cant delete a row

i cant delete a row on my table. when i click delete it say : "Insufficient key column information for updating or refreshing....." what can i do?The message smells like you might be using Microsoft Access to edit a table stored in Microsoft SQL, but that you don't have all of the defined key columns in the edit control. If that is correct:

1. Verify that there is a defined key
1a. Should be a PRIMARY KEY definition
1b. Could be a UNIQUE constraint
1c. Might be a UNIQUE INDEX
2. Identify all columns in all of the potential defined key(s) from step 1.
3. Ensure that all of the columns from at least one of the defined keys are present in your edit control.

-PatP|||thanks but i didnt use access. i copy and paste a row in my table. then i wanted to delete that row but i cant delete. all of my other rows can be cleaned but that row cant be delete.|||Nope, it isn't possible to "copy and paste a row in my table" because there isn't any GUI representation for a table. What you are doing (very possibly without realizing it) is copying and pasting within some application running on your machine, not actually on the table itself.

Since you haven't given us (the readers) many clues, but you have ruled out Microsoft Access, I'll make another guess... This time I'll guess Captain Peacock, in the Drawing Room... Oh wait, wrong game! ;)

Let's try this guess: Are you possibly using SQL Enterprise Manager, and Editing a table grid control? If so, please let me know and we can start to solve your problem... If not, I might try to guess again!

Just in case you didn't get the idea, I'm frustrated. You're asking me to help you solve a problem, but you haven't given me anything concrete to work from. I assume that you are using SQL Server, and that you haven't used it very much so you're handicapped in explaining your problem, and it appears that English isn't your native language which would further complicate things for you... I'm trying to help, but I need you to help me more so that I can help you!

If you can read English comfortably, please see this forum's FAQ for Brett Kaiser's excellent suggestions for How to Ask a Question to Get Quick and Correct Answers (http://www.dbforums.com/showthread.php?t=1212452#post4527530).

-PatP|||yes! you are right. im sorry. now i am using sql server 2000 enterprise manager. i create a table (same nortwind "order details"). remember i create an olap cube such as nwind
here is my fields:

accountno (varchar50)
medicineno(nvarchar15)
saleprice(float8)
quantity(float8)

i click return all rows and enter my records

1 101 $4 3
1 102 $3 2
2 102 $5 3
3 207 $2 1
....................
56 101 $4 2

and then i copy this row (2 102 $3 2) and paste it

........................
56 101 $4 2
2 102 $3 2

then i wanted to delete that row (2 102 $3 2)
but it cant be deleted. warning: "key column info insufficient or wrong. updating affects more rows" (i translated english. maybe it can be wrong)|||Have dealt with this in the past dealing with others issues.

You need to write a delete statment to accomplish this in query analyzer.

delete from table where accountno = 2

try inserting a new row as follows|||The problem stems from the fact that you do not have a unique primary key defined on your table. Thus, when you try to delete one record SQL Server cannot tell which record it is.
Add a primary key to your table. A surrogate key will do fine. But I also agree that you should not edit data from the Enterprise Manager GUI. Use Query Analyzer.|||thanks i will try

I cant create a temp table

Hi everyone,

I saw a post of this, but i still can't solve it.
This is what i got:
SET @.sql = 'CREATE TABLE #SIAG_MatrizTemporal ...'
EXEC(@.sql)

this seems to work fine, but if i try to make a query on #SIAG_MatrizTemporal, the table doesn't exists, the error says: "Invalid object name '#SIAG_MatrizTemporal'."

If I add to @.sql a select statement the values are in there, but if i do it outside the same string, it just doesn't work.

Joseph Weinstein says that i should add "selectMode=cursor" where should i add it ?? I'm just working with the stored procedure, i'm not using VS, Java or any other programming language. Later i have to use it from SQL Reporting Services, but first i have to make it work from the Query Analyzer...

I think i have to activate or desactivate some property on the Server or the query, but i was looking in Internet and nothing... I really need to solve this, and i cant find anything that works.

If anyone can help me, i really appreciate it.
Thanks in advance :)

JoanSET @.sql = 'CREATE TABLE ##SIAG_MatrizTemporal ...'
EXEC(@.sql)

You can use ##SIAG_MatrizTemporal to Dispose.
我不懂英文!
这里你必须使用全局临时表。
follow is my code. ex:

IF EXISTS
(SELECT * FROM tempdb..sysobjects WHERE name LIKE '##fabtemp%')
DROP TABLE ##fabtemp

EXEC ('
SELECT GUID=NEWID(),MstGUID = ''' + @.MstGUID + ''',
iNumber = IDENTITY(int, 1,1),
sRollNo,MaterialGUID,sLotNo,
sStoragePlaceCD,sStkTypeCD,
sSupplySourceCD,
fAccountQty = fOnHandQty + fOnHoldQty,
fRealQty = fOnHandQty + fOnHoldQty,fProfitOrLossQty = 0,
sCtUid = ''' + @.sUserID + ''',
dCtDate = GETDATE() INTO ##fabtemp
FROM IMFabricRollStock
WHERE sStorageCD = ''' + @.sStorageCD + '''' + @.sCondition +
'ORDER BY sStoragePlaceCD ')

/*------------------
------------------*/

INSERT INTO imFabricCheckingDtl
SELECT * FROM ##fabtemp

Wednesday, March 21, 2012

I cant create a temp table

Hi all!
I have a problem with a temp table.
I start creating my table:

bdsqlado.execute ("CREATE TABLE #MyTable ...")

There is no error. The sql string has been tested and when it's
executed in the sql query analyzer it really creates the table.

After creating the table, I execute an insert statement:

bdsqlado.execute ("INSERT INTO #MyTable VALUES(...) "

It returns an error like this: "Invalid Object Name #MyTable"

I don't understand what's wrong. If I execute both sql sentences in
the SQL Query Analyzer it works perfectly.
I use the same connection to execute both statements and I don't close
it before the INSERT is executed.
I think it may be something related to dynamic properties of the
connection, but I'm not sure. It's just an idea.

Please I need help.

Thanks a lot,
Sergio wrote:

> Hi all!
> I have a problem with a temp table.
> I start creating my table:
> bdsqlado.execute ("CREATE TABLE #MyTable ...")
> There is no error. The sql string has been tested and when it's
> executed in the sql query analyzer it really creates the table.
> After creating the table, I execute an insert statement:
> bdsqlado.execute ("INSERT INTO #MyTable VALUES(...) "
> It returns an error like this: "Invalid Object Name #MyTable"

Hi. Let me play Kreskin... I'm guesing you're using JDBC, and MS's
free driver. If this is true, add the property selectMode=cursor to
your connection properties. What is happening is that the driver
*is spawning multiple actual DBMS connections* to support a
single logical connection having multiple concurrent open statements.
This means the spid of one statement will be different than another, and
therefore one statement will not be able to see another's temp table!

Joe Weinstein

>
> I don't understand what's wrong. If I execute both sql sentences in
> the SQL Query Analyzer it works perfectly.
> I use the same connection to execute both statements and I don't close
> it before the INSERT is executed.
> I think it may be something related to dynamic properties of the
> connection, but I'm not sure. It's just an idea.
> Please I need help.
> Thanks a lot,

I can't create a table in TEMPDB

I have a USER wich can Create tables in the production DB, but this USER
can't create tables in TEMPDB.
? What's grong ?Does the user have access to TEMPDB database?
"Eduardo6973" <Eduardo6973@.discussions.microsoft.com> wrote in message
news:DC6F4810-17F5-4E3E-A59B-EAE30255E02F@.microsoft.com...
>I have a USER wich can Create tables in the production DB, but this USER
> can't create tables in TEMPDB.
> What's grong ?|||It's unusual to create non-temporary tables in tempdb. Can you elaborate on
why you need to do this? Perhaps there is an alternate approach.
All users have permissions to create local or global temp tables in tempdb
but CREATE TABLE permission is needed to create 'permanent' tables.
Non-sysadmin role members access tempdb under the guest user security
context so you could grant CREATE TABLE to guest so that non-sysadmin users
can create permanent tables owned by guest in tempdb. Alternatively, you
could add users to tempdb and then grant CREATE TABLE permissions to those
users. However, note that tempdb is recreated at instance startup so all
users, permissions and objects created in tempdb will lost. You'll need to
either reapply those permissions at startup or add the permissions to the
model database.
Hope this helps.
Dan Guzman
SQL Server MVP
"Eduardo6973" <Eduardo6973@.discussions.microsoft.com> wrote in message
news:DC6F4810-17F5-4E3E-A59B-EAE30255E02F@.microsoft.com...
>I have a USER wich can Create tables in the production DB, but this USER
> can't create tables in TEMPDB.
> What's grong ?

I cannot view table content in MS SQL Server Express

I was able to view table content easily before, but after I
reinstalled everything, I cannot find the option to view table content
in MS SQL Server Express. I can define table with no problem. Check
out the screen snapshot below, from which you'll see that the popup
menu frrom right-clicking on the table name does not have the "Open
table" option. What is going on?

http://farm1.static.flickr.com/167/...839620d0b_o.pngIt seems you are not connected to an SQL Server Express Edition
server. Instead, you are connected to a SQL Server Compact Edition
server, which is a different thing.

Razvan|||On Mar 19, 1:55 am, "Razvan Socol" <rso...@.gmail.comwrote:

Quote:

Originally Posted by

It seems you are not connected to an SQL Server Express Edition
server. Instead, you are connected to a SQL Server Compact Edition
server, which is a different thing.
>
Razvan


Yes, yes, you are very right. I also notice that. But how come? I
did download the package from the SQL Server Express website. It is
the one which says "Microsoft SQL Server 2005 Express Edition with
Advanced Services". The installation file has a name SQLEXPR_ADV.EXE,
which is 256M.

Is this the right one? Well, at installation, I did custom install
and made all components available from the local machine.

Pls give me hint, how do I properly install the Express Edition
instead of the compact Edition?

Thanks.|||I guess that both SQL Express and SQL Compact are installed now. It's
only a matter of connecting to the desired one. When the "Connect to
Server" dialog appears in Management Studio Express, make sure you
choose "Database Engine" in the "Server type" combo (instead of "SQL
Server Compact Edition").

Razvan|||On Mar 19, 12:07 pm, "Razvan Socol" <rso...@.gmail.comwrote:

Quote:

Originally Posted by

I guess that both SQL Express and SQL Compact are installed now. It's
only a matter of connecting to the desired one. When the "Connect to
Server" dialog appears in Management Studio Express, make sure you
choose "Database Engine" in the "Server type" combo (instead of "SQL
Server Compact Edition").
>
Razvan


You are right again. Yes, both "Database Engine" and "Sql Server
Compact Edition" show up in the combo. The problem is that I cannot
connect to .\SQLEXPRESS with Database Engine selected, using Windows
Authentication.|||[...] I cannot connect to .\SQLEXPRESS with Database Engine selected,

Quote:

Originally Posted by

using Windows Authentication.


What error message do you get (below "Cannot connect to .
\SQLEXPRESS") ?
a) "An error has occurred while establishing a connection to the
server [...] Error Locating Server/Instance Specified"
b) "Login failed for user 'COMPUTERNAME\username'"

I guess that a). In this case, go to Start / Programs / SQL Server
2005 / Configuration Tools / SQL Server Configuration Manager. Under
"SQL Server 2005 Services" do you have any entry with the "SQL Server"
as the "Service Type" ?

If yes, try to connect to the instance name specified there (if it's
the default instance, just try to connect to ".").

If no, then the Database Engine seems to be not installed; when you
reinstall SQL Server, make sure that "Data files" and "Shared tools"
under "Database Services" are selected. Then remember what choice you
make in the Instance Name screen.

Razvan|||On Mar 19, 3:44 pm, "Razvan Socol" <rso...@.gmail.comwrote:

Quote:

Originally Posted by

Quote:

Originally Posted by

[...] I cannot connect to .\SQLEXPRESS with Database Engine selected,
using Windows Authentication.


>
What error message do you get (below "Cannot connect to .
\SQLEXPRESS") ?
a) "An error has occurred while establishing a connection to the
server [...] Error Locating Server/Instance Specified"
b) "Login failed for user 'COMPUTERNAME\username'"
>
I guess that a). In this case, go to Start / Programs / SQL Server
2005 / Configuration Tools / SQL Server Configuration Manager. Under
"SQL Server 2005 Services" do you have any entry with the "SQL Server"
as the "Service Type" ?
>
If yes, try to connect to the instance name specified there (if it's
the default instance, just try to connect to ".").
>
If no, then the Database Engine seems to be not installed; when you
reinstall SQL Server, make sure that "Data files" and "Shared tools"
under "Database Services" are selected. Then remember what choice you
make in the Instance Name screen.
>
Razvan


Hey, Razvan, you really rock!

Exactly that was the problem. I checked the configuration manager.
It looks like that I don't have SQLEXPRESS. The instance name seems
to be MSSQLSERVER.

My computer name is EMACHINEXPPRO and I can connect to the SQL Server
by typing in this computer name as the Database Engine or like you
said, simply put a dot (.) instead.

Connecting to MSSQLSERVER or .\MSSQLSERVER results in error (error
code 53 or error code 87). See the screen snapshot below.

http://farm1.static.flickr.com/175/...8f5145e32_o.png
Good that I can connect to it using my computer name now. Many
thanks.

AL