Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Friday, March 30, 2012

MS SQL vs free Databases

Hello

I need to write an application which must use a database system as a backend, but i have not choosed which one to use. MySQL and PostgreSQL has all the features i want. the most important is database performance. anyone has an idea which database performs faster?

thanks in advance

Well, since you're on the MSDN forums, I'll go ahead and recommend the obvious: try SQL Express or MSDE :-)...|||

Hi,

well SQL Server Express is very powerful, fast, and has rich features. There are normally other conditions that have to be kept in mind while decideing, but if you ask people in a MSDN group, I would say go the Express Way :-)

-Jens Suessmeyer.

http://www.sqlserver2005.de

|||

If you are writing an app from scratch, I'd say you are by far best of using .NET development on a SQL Express platform. You are dealing with the latest and most efficient development platform, the most supported platform, and one that is expandable down the road. And it is cheap to get in at entry level

If you hit a home run, you want to at least have the option of scaling up and up all the way to SQL Enterprise with failover clustered servers.

I don't dream too big, do I? ;-)

|||

A major consideration for your choice of database should include not only features and performance, but the development environment. You really need to consider the OS, programming languages, and tools that you want to use. If you have developers who are proficient with Microsoft technologies (i.e., .Net) then SQL Server is an obvious choice. SQL Server and .Net provide everything you need and there is a ton of documentation, sites, books, webcasts, etc. ad nauseam.

PostgreSQL is powerful and interesting. It supports many languages (C, PL/Python, PL/Perl, PL/pgSQL), but development in the open-source environment is a radical shift from the widespread commercial support of MS or Oracle. You will need to be very proficient at coding many things from scratch, finding open-source tools and support sites, etc. Also, while learning PostgreSQL, I found that it's backup and recovery features were years behind Oracle. So, if your application will be enterprise class, you need to closely examine backup and recovery and high availability features. If your production database goes down, "who you gonna call"? (BTW, there are lists you can subscribe to to get email support from the PostgreSQL developers, but it's not "official" support like you get with MS or Oracle.) Check out www.postgresql.org as a starting point. I cannot recommend highly enough the PostgreSQL Bootcamp at www.bignerdranch.com.

I don't know Jack about MySQL.

Good luck and choose wisely!

|||

i can study u plen.

MS SQL stored procedures inside another stored procedure

Hi,

Do you know how to write stored procedures inside another stored procedure in MS SQL.

Create procedure spMyProc inputData varchar(50)

AS

-- some logical

procedure spMyProc inputInsideData varchar(10)

AS

-- some logical

-- go

---

What exactly are tou trying to do?

|||

Like Function, you can have one function inside another another function.

Function1 ()

{

Function2()

}

How about store procedure ?

spProc1

{

spProc2

}

how to write it with correct syntax?

|||

What do you mean by "having" a proc inside another proc? Execute a proc or create a proc? You can definetely call another proc but creating a proc from a proc is a very very bad idea.

|||

But, it is easy to migration. for example, currently, I have a base procedure and associated with several (5) satellite procedures, every time I have tell DBA, all of 6 proc.. I want to put into one.

|||

Hi,

First, just as ndinakar said, I also think it's not good to create a proc from a proc. You may create your procedure separately call your satellite procedures in your base procedure.

Second, if you really want to migratie all the procedures, then just put all the logic process code into one procedure, but it's also not a good way compared with the first method.

Thanks.

MS sql sever connection string

Hi everybody
Can anybody write a code and tell me how can i access a table called
KF_STATUS which is stored in MS SQL server2000. and it thas 3 fields called
KF_ID ,KF_DATE, and KF_STATUS and how can i display contents of those fields
--
Message posted via http://www.sqlmonster.comHi,
Access the table:-
1. Login to QUERY analyzer by providing the user name password
2. From the database pane, select the database where the KF_STATUS table
resides
3. Write the below query
select KF_ID ,KF_DATE, KF_STATUS FROM KF_STATUS
4. Execute the query by pressing Control and E simulteneously. This will
give u result.
THnaks
Hari
SQL Server MVP
"gurvinder gill via SQLMonster.com" <forum@.nospam.SQLMonster.com> wrote in
message news:f68623ec640847c497a4e72817032580@.SQLMonster.com...
> Hi everybody
> Can anybody write a code and tell me how can i access a table called
> KF_STATUS which is stored in MS SQL server2000. and it thas 3 fields
> called
> KF_ID ,KF_DATE, and KF_STATUS and how can i display contents of those
> fields
> --
> Message posted via http://www.sqlmonster.com

MS sql sever connection string

Hi everybody
Can anybody write a code and tell me how can i access a table called
KF_STATUS which is stored in MS SQL server2000. and it thas 3 fields called
KF_ID ,KF_DATE, and KF_STATUS and how can i display contents of those fields
Message posted via http://www.droptable.comHi,
Access the table:-
1. Login to QUERY analyzer by providing the user name password
2. From the database pane, select the database where the KF_STATUS table
resides
3. Write the below query
select KF_ID ,KF_DATE, KF_STATUS FROM KF_STATUS
4. Execute the query by pressing Control and E simulteneously. This will
give u result.
THnaks
Hari
SQL Server MVP
"gurvinder gill via droptable.com" <forum@.nospam.droptable.com> wrote in
message news:f68623ec640847c497a4e72817032580@.SQ
droptable.com...
> Hi everybody
> Can anybody write a code and tell me how can i access a table called
> KF_STATUS which is stored in MS SQL server2000. and it thas 3 fields
> called
> KF_ID ,KF_DATE, and KF_STATUS and how can i display contents of those
> fields
> --
> Message posted via http://www.droptable.comsql

Wednesday, March 28, 2012

MS sql sever connection string

Hi everybody
Can anybody write a code and tell me how can i access a table called
KF_STATUS which is stored in MS SQL server2000. and it thas 3 fields called
KF_ID ,KF_DATE, and KF_STATUS and how can i display contents of those fields
Message posted via http://www.droptable.com
Hi,
Access the table:-
1. Login to QUERY analyzer by providing the user name password
2. From the database pane, select the database where the KF_STATUS table
resides
3. Write the below query
select KF_ID ,KF_DATE, KF_STATUS FROM KF_STATUS
4. Execute the query by pressing Control and E simulteneously. This will
give u result.
THnaks
Hari
SQL Server MVP
"gurvinder gill via droptable.com" <forum@.nospam.droptable.com> wrote in
message news:f68623ec640847c497a4e72817032580@.droptable.co m...
> Hi everybody
> Can anybody write a code and tell me how can i access a table called
> KF_STATUS which is stored in MS SQL server2000. and it thas 3 fields
> called
> KF_ID ,KF_DATE, and KF_STATUS and how can i display contents of those
> fields
> --
> Message posted via http://www.droptable.com

Wednesday, March 21, 2012

MS SQL Server 2000 & ADP Write Conflict Error


Im new to SQL and am having some difficulty.
I created a DB that has about 5 tables, all of which are related via the
client_id column.
I created a trigger which upon insert into my main table shoots the
client_id into the corresponding column in the other tables.
My front end is a MS ADP project. When I try to insert a new record
with "ALL" the fields in my MS Access ADP Form filled in I get a "Write
COnflict" Error. But when I try to insert a new record with "ONLY"
filling in the client_id filed the record is created without a proble?
Can anyone help me?
*** Sent via Developersdex http://www.examnotes.net ***Two possible things to check...
1. Do any of the other tables have columns that do not permit null?
If so, when the trigger tries to do the insert, you can't complete.
2. Is the ForeignKey in any of the tables you are writing to, .. identity.
If so, you are creating a duplicate.
"Anon" <anonymous@.devdex.com> wrote in message
news:OLHVYmlMGHA.3732@.TK2MSFTNGP10.phx.gbl...
>
> Im new to SQL and am having some difficulty.
> I created a DB that has about 5 tables, all of which are related via the
> client_id column.
> I created a trigger which upon insert into my main table shoots the
> client_id into the corresponding column in the other tables.
> My front end is a MS ADP project. When I try to insert a new record
> with "ALL" the fields in my MS Access ADP Form filled in I get a "Write
> COnflict" Error. But when I try to insert a new record with "ONLY"
> filling in the client_id filed the record is created without a proble?
> Can anyone help me?
>
> *** Sent via Developersdex http://www.examnotes.net ***|||1. I added a default value to the columns in the "other" tables that do
not allow nulls
2. The foreignkeys in all the other tables are the primary keys...if
that makes any sense (Is there a work around?)
Two possible things to check...
1. Do any of the other tables have columns that do not permit null?
If so, when the trigger tries to do the insert, you can't complete.
2. Is the ForeignKey in any of the tables you are writing to, ..
identity.
If so, you are creating a duplicate.
-RS
*** Sent via Developersdex http://www.examnotes.net ***|||1. I added a default value to the columns in the "other" tables that do
not allow nulls
2. The foreignkeys in all the other tables are the primary keys...if
that makes any sense (Is there a work around?)
Two possible things to check...
1. Do any of the other tables have columns that do not permit null?
If so, when the trigger tries to do the insert, you can't complete.
2. Is the ForeignKey in any of the tables you are writing to, ..
identity.
If so, you are creating a duplicate.
-RS
*** Sent via Developersdex http://www.examnotes.net ***sql

Monday, March 19, 2012

MS SQL Server - a plethora of limitations...

Why is it, Microsoft manage to write operating systems and office
applications with every bell and whistle facility known to man. Yet,
even after years and years of development they still cannot produce a
decent version of MS SQL Server, one without a plethora of flaws and
limitations? Personally I'd sack the MS SQL Server Chief Architect,
start addressing some fundementals and do what MS do best - copy the
best functionality of their competitors.

Here's a few reasons why I feel MS SQL Server is still a load of crap,
and will never be many developers RDBMS of choice :

1. Can't use domains in Multi-statement table-valued function table
definition

2. No concept of table.column.datatype MYTABLE.MYCOLUMN%TYPE for
function / proc parameters, variables. Schema evolution will require
changes to dep functions / procs.

3. Cannot call non extended user defined procedure from within stored
proc - prevents code re-use

4. No create or replace for functions / procs. Changes to procs
require either a change from create to alter, or drop then create

5. Functions must return result on final statement - requires
excessive use of local variables. Why!!!?

6. No user specifiable date format routines - must use convert with
limited options

7. No treewalk mechanism, not easy to traverse hierarchical structure

8. Calling procedures with out parameters require user to also
specifiy which are out params

9. Stored Proc recursion limitations to only 32 nested levels, rather
than monitoring by stack size.

10. No on delete set null referential integrity, this is fundemental
in relational databases, has to be done by trigger. Yuk.

11. No partitioning on db tables

12. Cannot raiseerror in stored functions. No way to inform user of
incorrect parameters etc.

13. No facility for sub - procs / funcs - for localised code
normalisation.

14. No function overloading

15. No concept of grouping similar procs / functions into a collective
package - can mean 1000s of procs rather than a handful of packages.

16. Non standard func / proc calling - proc non parenthesised but,
function defined and called with parenthesis

17. Limited column name length in table variables / Multi-statement
table-valued function table definitions

18. No intersect, minus operators to complement union and union all

19. No exception handling - need I say more about this fundemental
requirement?

20. No handling for select statements using proc parameters passed in
as null e.g.
create procedure sp_test......
.....

select @.MyID = ID
from mytable
where parent_id = @.parent_id.

If @.parent_id is null, select will not return anything even if values
for null parent_id exist.

21 No boolean type for use in stored procs / funcs. SQL standards do
allow booleans (null, FALSE, TRUE)

22 No repeat until - (post predicate loops), while loops can perform
this but one extra check often has to be performed

23 No equivalent to cursor or table %ROWTYPE, when fetching from a
many column cursor, all bind variables have to be declared
individually

24. Declarative Delete cascade in SQL Server is at best rubbish - e.g.
No table can appear more than once in the list of all cascading
referential actions that result from the DELETE or UPDATE. Almost all
other RDBMS I've tried seems to manage it.

Create Table ForKey
(
MyID int not null identity primary key,
MyText varchar(30)
)
go

Create Table Refs
(
SomeID int not null primary key,
RefID1 int not null foreign key references ForKey(MyID) on delete
cascade,
RefID2 int not null foreign key references ForKey(MyID) on delete
cascade
)

Server: Msg 1785, Level 16, State 1, Line 2
Introducing FOREIGN KEY constraint 'FK__Refs__RefID2__1BFD2C07' on
table 'Refs' may cause cycles or multiple
cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or
modify other FOREIGN KEY constraints.
Server: Msg 1750, Level 16, State 1, Line 2
Could not create constraint. See previous errors.

25. Domains cannot be altered without dropping all dependencies
(stored procs / funcs) even if type isn't changed but say scale and
precision- this is ridiculous. What is the point of domains?

26. No "for loop", while loops can perform this, but resultant code is
not as clear or tidy

27. Can't use CURDATE() inside stored procs / funcs. How crap is
that?

Don't try and make excuses for MS as I have hundreds, anyone else have
any?

JeagerComments inline.

> 1. Can't use domains in Multi-statement table-valued function table
> definition

User-defined datatypes? That may be addressed in Yukon which has UDTs. (I
know, "jam tomorrow...")

> 2. No concept of table.column.datatype MYTABLE.MYCOLUMN%TYPE for
> function / proc parameters, variables. Schema evolution will require
> changes to dep functions / procs.

True. Although the changes addressed by Oracle's column and row type
functions are surely a fairly small subset of the code maintenance required
when the schema changes.

> 3. Cannot call non extended user defined procedure from within stored
> proc - prevents code re-use

You *can* do that. You can't call SPs from within a UDF and there are good
reasons why not (determinism).

> 4. No create or replace for functions / procs. Changes to procs
> require either a change from create to alter, or drop then create

That would indeed be a nice feature to have.

> 5. Functions must return result on final statement - requires
> excessive use of local variables. Why!!!?

Not sure what this means.

> 6. No user specifiable date format routines - must use convert with
> limited options

You can code your own but converting date strings is really an ETL
function - use DTS or some other tool.

> 7. No treewalk mechanism, not easy to traverse hierarchical structure

That's not quite correct. There isn't a non-iterative way to expand an
*adjacency list* hierarchy. Other hierarchy models make this easy to do.
CTEs in Yukon will address the limitation relevant to adjacency hierarchies.

> 8. Calling procedures with out parameters require user to also
> specifiy which are out params

Why is that a problem?

> 10. No on delete set null referential integrity, this is fundemental
> in relational databases, has to be done by trigger. Yuk.

I agree that's inconvenient.

> 11. No partitioning on db tables

Partitioned views are the SQLServer alternative.

> 12. Cannot raiseerror in stored functions. No way to inform user of
> incorrect parameters etc.

True, that's a little annoying.

> 9. Stored Proc recursion limitations to only 32 nested levels, rather
> than monitoring by stack size.
> 13. No facility for sub - procs / funcs - for localised code
> normalisation.
> 14. No function overloading
> 15. No concept of grouping similar procs / functions into a collective
> package - can mean 1000s of procs rather than a handful of packages.
> 16. Non standard func / proc calling - proc non parenthesised but,
> function defined and called with parenthesis

> 26. No "for loop", while loops can perform this, but resultant code is
> not as clear or tidy

Transact SQL isn't intended to be a fully featured programming language.
..Net is Microsoft's development platform. Keep basic data manipulation in
the database, more complex logic in the middle tier.

> 17. Limited column name length in table variables / Multi-statement
> table-valued function table definitions

Do you know of a database or language that allows identifiers of *un*limited
length? The maximum length is 128 characters. Surely enough for most people!

> 18. No intersect, minus operators to complement union and union all

True. Although this is trivial to code yourself.

> 19. No exception handling - need I say more about this fundemental
> requirement?

Error handling is improved in Yukon but yes it's a pain.

> 20. No handling for select statements using proc parameters passed in
> as null e.g.
> create procedure sp_test......
> ....
> select @.MyID = ID
> from mytable
> where parent_id = @.parent_id.
> If @.parent_id is null, select will not return anything even if values
> for null parent_id exist.

That's just ANSI Standard handling of NULLs. Use IS NULL.

> 21 No boolean type for use in stored procs / funcs. SQL standards do
> allow booleans (null, FALSE, TRUE)

No, but you can return "T" or "F" or something else instead. Why is that a
limitation? It's still just a single scalar value.

> 22 No repeat until - (post predicate loops), while loops can perform
> this but one extra check often has to be performed

Yes.

> 23 No equivalent to cursor or table %ROWTYPE, when fetching from a
> many column cursor, all bind variables have to be declared
> individually

How often do you use cursors? I don't think I've ever written one except for
some administrative processes.

> 24. Declarative Delete cascade in SQL Server is at best rubbish - e.g.
> No table can appear more than once in the list of all cascading

This is a significant limitation, yes.

> 25. ... What is the point of domains?

You said it. Personally, I never use user-defined datatypes.

> 27. Can't use CURDATE() inside stored procs / funcs. How crap is
> that?

You can use CURRENT_TIMESTAMP, GETDATE() in procs but not in functions. See
my answer to 3.

> Don't try and make excuses for MS as I have hundreds, anyone else have
> any?

Lots. But if it bothers you why not use another product?

--
David Portas
SQL Server MVP
--|||Comments inline.

> 1. Can't use domains in Multi-statement table-valued function table
> definition

User-defined datatypes? That may be addressed in Yukon which has UDTs. (I
know, "jam tomorrow...")

> 2. No concept of table.column.datatype MYTABLE.MYCOLUMN%TYPE for
> function / proc parameters, variables. Schema evolution will require
> changes to dep functions / procs.

True. Although the changes addressed by Oracle's column and row type
functions are surely a fairly small subset of the code maintenance required
when the schema changes.

> 3. Cannot call non extended user defined procedure from within stored
> proc - prevents code re-use

You *can* do that. You can't call SPs from within a UDF and there are good
reasons why not (determinism).

> 4. No create or replace for functions / procs. Changes to procs
> require either a change from create to alter, or drop then create

That would indeed be a nice feature to have.

> 5. Functions must return result on final statement - requires
> excessive use of local variables. Why!!!?

Not sure what this means.

> 6. No user specifiable date format routines - must use convert with
> limited options

You can code your own but converting date strings is really an ETL
function - use DTS or some other tool.

> 7. No treewalk mechanism, not easy to traverse hierarchical structure

That's not quite correct. There isn't a non-iterative way to expand an
*adjacency list* hierarchy. Other hierarchy models make this easy to do.
CTEs in Yukon will address the limitation relevant to adjacency hierarchies.

> 8. Calling procedures with out parameters require user to also
> specifiy which are out params

Why is that a problem?

> 10. No on delete set null referential integrity, this is fundemental
> in relational databases, has to be done by trigger. Yuk.

I agree that's inconvenient.

> 11. No partitioning on db tables

Partitioned views are the SQLServer alternative.

> 12. Cannot raiseerror in stored functions. No way to inform user of
> incorrect parameters etc.

True, that's a little annoying.

> 9. Stored Proc recursion limitations to only 32 nested levels, rather
> than monitoring by stack size.
> 13. No facility for sub - procs / funcs - for localised code
> normalisation.
> 14. No function overloading
> 15. No concept of grouping similar procs / functions into a collective
> package - can mean 1000s of procs rather than a handful of packages.
> 16. Non standard func / proc calling - proc non parenthesised but,
> function defined and called with parenthesis

> 26. No "for loop", while loops can perform this, but resultant code is
> not as clear or tidy

Transact SQL isn't intended to be a fully featured programming language.
..Net is Microsoft's development platform. Keep basic data manipulation in
the database, more complex logic in the middle tier.

> 17. Limited column name length in table variables / Multi-statement
> table-valued function table definitions

Do you know of a database or language that allows identifiers of *un*limited
length? The maximum length is 128 characters. Surely enough for most people!

> 18. No intersect, minus operators to complement union and union all

True. Although this is trivial to code yourself.

> 19. No exception handling - need I say more about this fundemental
> requirement?

Error handling is improved in Yukon but yes it's a pain.

> 20. No handling for select statements using proc parameters passed in
> as null e.g.
> create procedure sp_test......
> ....
> select @.MyID = ID
> from mytable
> where parent_id = @.parent_id.
> If @.parent_id is null, select will not return anything even if values
> for null parent_id exist.

That's just ANSI Standard handling of NULLs. Use IS NULL.

> 21 No boolean type for use in stored procs / funcs. SQL standards do
> allow booleans (null, FALSE, TRUE)

No, but you can return "T" or "F" or something else instead. Why is that a
limitation? It's still just a single scalar value.

> 22 No repeat until - (post predicate loops), while loops can perform
> this but one extra check often has to be performed

Yes.

> 23 No equivalent to cursor or table %ROWTYPE, when fetching from a
> many column cursor, all bind variables have to be declared
> individually

How often do you use cursors? I don't think I've ever written one except for
some administrative processes.

> 24. Declarative Delete cascade in SQL Server is at best rubbish - e.g.
> No table can appear more than once in the list of all cascading

This is a significant limitation, yes.

> 25. ... What is the point of domains?

You said it. Personally, I never use user-defined datatypes.

> 27. Can't use CURDATE() inside stored procs / funcs. How crap is
> that?

You can use CURRENT_TIMESTAMP, GETDATE() in procs but not in functions. See
my answer to 3.

> Don't try and make excuses for MS as I have hundreds, anyone else have
> any?

Lots. But if it bothers you why not use another product?

--
David Portas
SQL Server MVP
--|||Jeager (Jeager@.nowhere.com) writes:
> Why is it, Microsoft manage to write operating systems and office
> applications with every bell and whistle facility known to man. Yet,
> even after years and years of development they still cannot produce a
> decent version of MS SQL Server, one without a plethora of flaws and
> limitations? Personally I'd sack the MS SQL Server Chief Architect,
> start addressing some fundementals and do what MS do best - copy the
> best functionality of their competitors.
> Here's a few reasons why I feel MS SQL Server is still a load of crap,
> and will never be many developers RDBMS of choice :

Some of the issues you raise are certainly weaknesses in SQL Server of
some significance. Some of them are addressed in the next version of
SQL Server, but not all.

However, other issues you raise, do in no way warrant your yelling
and shouting. Maybe you have a favourite DBMS which supports all this,
but I doubt. And that DBMS is such case likely to be without features
that SQL Server has.

> 1. Can't use domains in Multi-statement table-valued function table
> definition

You can't use domains anywhere, because SQL Server does not have the
concept. But if you mean user-defined datatypes, this is somewhat stupid
limitation.

> 2. No concept of table.column.datatype MYTABLE.MYCOLUMN%TYPE for
> function / proc parameters, variables. Schema evolution will require
> changes to dep functions / procs.

Would be nice, yes, but a serious restriction? No.

> 3. Cannot call non extended user defined procedure from within stored
> proc - prevents code re-use

Wrong. But you are probably thinking of calling an SP from a function.
It appears that you have not understood the concept of a function. When
MS introduced functions, they took a very conservative approach and
decided that a function may not change the state of the database. Of
course, they could have been more lax, but that would also have reduced
where you can use a function. Say that you have:

SELECT ...
FROM tbl
JOIN some_fuction() ON ..

Now, if some_function changes data in tbl, you could different results
depending in which order the optimizer accesses the table. Do you think
that would be a good thing?

> 4. No create or replace for functions / procs. Changes to procs
> require either a change from create to alter, or drop then create

No big deal. See http://www.abaris.se/abaperls which takes care of this
problem entirely. (And which also address the first issue on the list.)

> 5. Functions must return result on final statement - requires
> excessive use of local variables. Why!!!?

Come on, you call this a serious issue.

> 6. No user specifiable date format routines - must use convert with
> limited options

Then again, it's better to return as date to the client. The server
cannot now which the preferences of the end user are.

> 8. Calling procedures with out parameters require user to also
> specifiy which are out params

Funky. Part of the Sybase legacy.

> 9. Stored Proc recursion limitations to only 32 nested levels, rather
> than monitoring by stack size.

Probably a good thing. The only times when I have dug this deep was
then I shouldn't have.

> 10. No on delete set null referential integrity, this is fundemental
> in relational databases, has to be done by trigger. Yuk.

Fundamental?

> 11. No partitioning on db tables

You can use partitioned views. Partition tables are in Yukon.

> 12. Cannot raiseerror in stored functions. No way to inform user of
> incorrect parameters etc.

Given that SQL Server does not handle errors raised in functions well
at all, this is probably a good thing. :-)

> 14. No function overloading

And you are calling that a serious restriction? Well, in Yukon you will
be able to program in .Net languages, so there you be able to overload
to your hears content.

> 15. No concept of grouping similar procs / functions into a collective
> package - can mean 1000s of procs rather than a handful of packages.

Again, that is nothing that warrants the tone of your post.

> 16. Non standard func / proc calling - proc non parenthesised but,
> function defined and called with parenthesis

Irritating, but it's not the end of the world.

> 17. Limited column name length in table variables / Multi-statement
> table-valued function table definitions

Isn't 128 chars enough for you?

> 18. No intersect, minus operators to complement union and union all

Yes, this is missing, and no signs of being added either.

> 19. No exception handling - need I say more about this fundemental
> requirement?

Error handling in SQL2000 is really poor. Yukon changes the scene
radically.

> 20. No handling for select statements using proc parameters passed in
> as null e.g.
> create procedure sp_test......
> ....
> select @.MyID = ID
> from mytable
> where parent_id = @.parent_id.
> If @.parent_id is null, select will not return anything even if values
> for null parent_id exist.

Wrong. If you want this behaviour, you can use SET ANSI_NULLS OFF. But
I definitely to not encourage it.

> 21 No boolean type for use in stored procs / funcs. SQL standards do
> allow booleans (null, FALSE, TRUE)

There is bit. Works for me.

> 22 No repeat until - (post predicate loops), while loops can perform
> this but one extra check often has to be performed

If you want a language with good control structure, try a traditional
one. You will even be able to use them in SQL Server in Yukon.

> 23 No equivalent to cursor or table %ROWTYPE, when fetching from a
> many column cursor, all bind variables have to be declared
> individually

Big deal. Cursors are best avoided anyway.

> 25. Domains cannot be altered without dropping all dependencies
> (stored procs / funcs) even if type isn't changed but say scale and
> precision- this is ridiculous. What is the point of domains?

To alter them each and every day? I seriously doubt. Actually, this
is the sort of feature I don't know if I want to see. You have this
user-defined data type (still no domains in SQL Server), which is
decimal(8,2), and which is used in 15 big tables. Now you decide
to change the type decimal(14,2). Since you now make the type bigger,
SQL Server has to rebuild all tables. In one single transaction.

> 27. Can't use CURDATE() inside stored procs / funcs. How crap is
> that?

Probably you mean getdate(), which you can use in stored procedures.
You cannot use it functions, because when a function is called repeatedly
in a query, the result should be the save for any given input parameter
at time during the query.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Well guy I am a french SQL expert and recently became a MVP...

I now pretty well ISO standard SQL Language.

The state of art in the normative process is actually SQL:1992.
SQL:1999 wich has got relational object feature is not yet a ISO standard...

Let me say that, SQL Server is the RDBMS closest to the standard !

Do you know RDBMS wich allows database object names to be long to 128 chars ?
Do you know RDBMS wich use INFORMATION_SCHEMA views to meta data the data base ?
Do you know RDBMS wich use COALESCE and NULLIF function ?
Do you know RDBMS wich have the two structured CASE ?
Do you know RDBMS wich allow you to subqueries in the FROM clause of a SELECT ?
...

The thing you want will be a mix of Java, C, Excel, Ada but not a RDBMS !

Jeager a crit:
> Why is it, Microsoft manage to write operating systems and office
> applications with every bell and whistle facility known to man. Yet,
> even after years and years of development they still cannot produce a
> decent version of MS SQL Server, one without a plethora of flaws and
> limitations? Personally I'd sack the MS SQL Server Chief Architect,
> start addressing some fundementals and do what MS do best - copy the
> best functionality of their competitors.
> Here's a few reasons why I feel MS SQL Server is still a load of crap,
> and will never be many developers RDBMS of choice :
> 1. Can't use domains in Multi-statement table-valued function table
> definition

DOMAINs can be simulated by a combination of rules and UserType.

> 2. No concept of table.column.datatype MYTABLE.MYCOLUMN%TYPE for
> function / proc parameters, variables. Schema evolution will require
> changes to dep functions / procs.

Not OK for that ! We are not in a Ada ou C++ dev !

> 3. Cannot call non extended user defined procedure from within stored
> proc - prevents code re-use
> 4. No create or replace for functions / procs. Changes to procs
> require either a change from create to alter, or drop then create

Don't you use a tool ? Don't you use the script auto create of Enterprise Manager to get the SQL equivalent code ?

> 5. Functions must return result on final statement - requires
> excessive use of local variables. Why!!!?

This does not appear to be so stupid !
> 6. No user specifiable date format routines - must use convert with
> limited options

Wrong... use SET DATEFORMAT.

> 7. No treewalk mechanism, not easy to traverse hierarchical structure

Don't need. Every recursive process can be write without recursive code by use of a "pile" structure.
For instance, trees in SQL can be modelate by intervals.
Read me for that : http://sqlpro.developpez.com/Tree/SQL_tree.html

> 8. Calling procedures with out parameters require user to also
> specifiy which are out params

Is it really a problem ?
> 9. Stored Proc recursion limitations to only 32 nested levels, rather
> than monitoring by stack size.

Recursion processes in RDBMS should never exists. See answer 7.

> 10. No on delete set null referential integrity, this is fundemental
> in relational databases, has to be done by trigger. Yuk.

This is really a point !

> 11. No partitioning on db table
Manually !

> 12. Cannot raiseerror in stored functions. No way to inform user of
> incorrect parameters etc.

Yes this is the second point, the error manager of SQL Server must be improve !
> 13. No facility for sub - procs / funcs - for localised code
> normalisation.
> 14. No function overloading

SQL is not an OO language and must not be one ! The future of the standard does not goes in this way !
> 15. No concept of grouping similar procs / functions into a collective
> package - can mean 1000s of procs rather than a handful of packages.
Yes, but with a use of a 128 char name, you can group by prefix ! This is not the cas in Oracle wich cannot accept more
than 28 chars... And the real interest of package for this "poor" naming object database !

> 16. Non standard func / proc calling - proc non parenthesised but,
> function defined and called with parenthesis

The weight of the past... Procs was developped before the standard came, functions, after the standard and close to the
standar ...
> 17. Limited column name length in table variables / Multi-statement
> table-valued function table definitions

128 characters is not enough for you ? This is the SQL:1992 standard !

> 18. No intersect, minus operators to complement union and union all

Wich can be represented by two equivalents... But I agree, I would prefer they exists !
> 19. No exception handling - need I say more about this fundemental
> requirement?

"dj dit"
> 20. No handling for select statements using proc parameters passed in
> as null e.g.
> create procedure sp_test......
> ....
> select @.MyID = ID
> from mytable
> where parent_id = @.parent_id.
> If @.parent_id is null, select will not return anything even if values
> for null parent_id exist.

depend on the parameters fixed for normative NULL treatment

> 21 No boolean type for use in stored procs / funcs. SQL standards do
> allow booleans (null, FALSE, TRUE)

Wrong, the type is BIT, wich allow 1, 0, NULL. SQL does not have any standard about boolean. This is planed in SQL:199
wich is not yet a ISO standard !

> 22 No repeat until - (post predicate loops), while loops can perform
> this but one extra check often has to be performed

not really a problem WHILE is a general loop that can replace all.
> 23 No equivalent to cursor or table %ROWTYPE, when fetching from a
> many column cursor, all bind variables have to be declared
> individually

A lack, I agree

> 24. Declarative Delete cascade in SQL Server is at best rubbish - e.g.
> No table can appear more than once in the list of all cascading
> referential actions that result from the DELETE or UPDATE. Almost all
> other RDBMS I've tried seems to manage it.

The use of CASCADED delete or update is always a performance problem. This limitation has a good intention... The use of
a trigger is better !
> Create Table ForKey
> (
> MyID int not null identity primary key,
> MyText varchar(30)
> )
> go
> Create Table Refs
> (
> SomeID int not null primary key,
> RefID1 int not null foreign key references ForKey(MyID) on delete
> cascade,
> RefID2 int not null foreign key references ForKey(MyID) on delete
> cascade
> )
> Server: Msg 1785, Level 16, State 1, Line 2
> Introducing FOREIGN KEY constraint 'FK__Refs__RefID2__1BFD2C07' on
> table 'Refs' may cause cycles or multiple
> cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or
> modify other FOREIGN KEY constraints.
> Server: Msg 1750, Level 16, State 1, Line 2
> Could not create constraint. See previous errors.
> 25. Domains cannot be altered without dropping all dependencies
> (stored procs / funcs) even if type isn't changed but say scale and
> precision- this is ridiculous. What is the point of domains?
>
> 26. No "for loop", while loops can perform this, but resultant code is
> not as clear or tidy

Redondant with 22
> 27. Can't use CURDATE() inside stored procs / funcs. How crap is
> that?
In Stored Proc Yes, In Function not. Because of DETERMINISTIC limitation.
You can use a view instaed :

CREATE VIEW GIVE_ME_CURRENT_DATETIME
AS
SELECT CURRENT_TIMESTAMP AS DT

CREATE FUNCTION dbo.FN_GETDATETIME
RETURNS DATETIME
BEGIN
RETURN (SELECT DT FROM GIVE_ME_CURRENT_DATETIME)
END

By the way, CURRENT_TIMESTAMP is the SQL:1992 standard of datetime function !

> Don't try and make excuses for MS as I have hundreds, anyone else have
> any?

For me the most important lack is the deferability of constraint...
wich is a SQL:1992 standard

One important point, wich is not a SQL standard, but planned for SQL:1999 is that SQL Server does not allow BEFORE trigger.

And some point I will be enjoy to have is :
ROW VALUE CONSTRUCTOR
MATCH predicate
and some other standard stuff like EXTRACT, OVERLAPS and INTERVAL data type (time process)

> Jeager

--
Frdric BROUARD, MVP SQL Server. Expert SQL / spcialiste Delphi, web
Livre SQL - col. Rfrence : http://sqlpro.developpez.com/bookSQL.html
Le site du SQL, pour dbutants et pros : http://sqlpro.developpez.com
************************ www.datasapiens.com *************************|||Fred BROUARD - SQLpro (brouardf@.club-internet.fr) writes:
> Let me say that, SQL Server is the RDBMS closest to the standard !

Hey, would you expect anyone who thinks that NULL should be equal to
NULL would care about standards?

(Sorry, could not resist.)

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Fred BROUARD - SQLpro wrote:
> Well guy I am a french SQL expert and recently became a MVP...
> I now pretty well ISO standard SQL Language.
> The state of art in the normative process is actually SQL:1992.
> SQL:1999 wich has got relational object feature is not yet a ISO
> standard...
> Let me say that, SQL Server is the RDBMS closest to the standard !
I like that French humour of yours :-)
SQL:1999 is outdated itself, btw.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab|||"Fred BROUARD - SQLpro" <brouardf@.club-internet.fr> wrote in message
news:40c8d44e$0$308$7a628cd7@.news.club-internet.fr...
> Well guy I am a french SQL expert and recently became a MVP...
> I now pretty well ISO standard SQL Language.
> The state of art in the normative process is actually SQL:1992.
> SQL:1999 wich has got relational object feature is not yet a ISO standard...
> Let me say that, SQL Server is the RDBMS closest to the standard !
> Do you know RDBMS wich allows database object names to be long to 128 chars ?
> Do you know RDBMS wich use INFORMATION_SCHEMA views to meta data the data base ?
> Do you know RDBMS wich use COALESCE and NULLIF function ?
> Do you know RDBMS wich have the two structured CASE ?
> Do you know RDBMS wich allow you to subqueries in the FROM clause of a SELECT ?
> ...

Adaptive Server Anywhere from Sybase's iAnywhere group has all those features except INFORMATION_SCHEMA. I believe
that's planned for their next release - v10.0.

--
Paul Horan
Sr. Architect
VCI Springfield, Mass
www.vcisolutions.com|||Erland Sommarskog wrote:

> Fred BROUARD - SQLpro (brouardf@.club-internet.fr) writes:
>>Let me say that, SQL Server is the RDBMS closest to the standard !
>
> Hey, would you expect anyone who thinks that NULL should be equal to
> NULL would care about standards?
> (Sorry, could not resist.)

I think that NULL is used for three separate concepts, unknown,
absent and not applicable (would turn up in queries, due to outer
joins). Absent should be equal to absent, unknown should *not*
be equal to unknown, and I'm not really sure about not applicable.
To do all that, though, one kind of Null isn't enough. I blame
SQL for this, however, not MS SQL.

Bill|||Jeager wrote:

> Why is it, Microsoft manage to write operating systems and office
> applications with every bell and whistle facility known to man. Yet,
> even after years and years of development they still cannot produce a
> decent version of MS SQL Server, one without a plethora of flaws and
> limitations? Personally I'd sack the MS SQL Server Chief Architect,
> start addressing some fundementals and do what MS do best - copy the
> best functionality of their competitors.

> 2. No concept of table.column.datatype MYTABLE.MYCOLUMN%TYPE for
> function / proc parameters, variables. Schema evolution will require
> changes to dep functions / procs.
Do you mean that you can't use variables for database objects (this
really bugs me)? If not, I have no idea what you're saying here.

> 21 No boolean type for use in stored procs / funcs. SQL standards do
> allow booleans (null, FALSE, TRUE)
What about boolean types for use within queries? Personally, I'm sick
of writing "Case When Field1 = Field2 Then 1 Else 0 End As Equals". It
should just be "(Field1 = Field2) As Equals".

Bill|||Just to set the record straight, since we're listing...:-P

> Let me say that, SQL Server is the RDBMS closest to the standard !
> Do you know RDBMS wich allows database object names to be long to 128 chars ?
Yes, DB2/UDB does as well as SQLServer. Oracle needs to catch up
here.
> Do you know RDBMS wich use INFORMATION_SCHEMA views to meta data the data base ?
Yes, Oracle has more data dictionary views than you can shake a stick
at. There's a data dictionary view to find anything you can possibly
imagine, including access to memory structures. SQLServer and DB2/UDB
are both woefully lacking in this area.
> Do you know RDBMS wich use COALESCE and NULLIF function ?
All three.
> Do you know RDBMS wich have the two structured CASE ?
All three.
> Do you know RDBMS wich allow you to subqueries in the FROM clause of a SELECT ?
All three.
> ...|||On Tue, 15 Jun 2004 01:55:32 GMT, William Cleveland wrote:

> What about boolean types for use within queries? Personally, I'm sick
> of writing "Case When Field1 = Field2 Then 1 Else 0 End As Equals". It
> should just be "(Field1 = Field2) As Equals".

Use a UDF. Shouldn't add to overhead, adds clarity.

AreEqual(Field1,Field2) As Equals|||Ross Presser (rpresser@.imtek.com) writes:
> Use a UDF. Shouldn't add to overhead, adds clarity.
> AreEqual(Field1,Field2) As Equals

Would have to write one for each datatype. And, as always with scalar
UDFs, the performance cost may not be the worth the gain in clarity.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||>> I think that NULL is used for three separate concepts, unknown, absent
and not applicable <<

Why stop at just three? There are several other meanings assigned to NULLs
in SQL including indeterminate value, unsupplied value, non-existent value,
empty set...sadly, as you mentioned, using standard 3VL for all such missing
information handling is an obvious SQL kludge.

--
Anith

Ms Sql Query

I am trying to write a query that will choose a row without duplicates. The table is used as a checking in/out log and I need to query the latest check in or out. There is a column that is in date-time format that records the time of the check in or out, so inside of my query, how can I grab all of the distinct rows, choosing the latest check in or out transaction for each user?

Quote:

Originally Posted by mbarnes2231

I am trying to write a query that will choose a row without duplicates. The table is used as a checking in/out log and I need to query the latest check in or out. There is a column that is in date-time format that records the time of the check in or out, so inside of my query, how can I grab all of the distinct rows, choosing the latest check in or out transaction for each user?

Please try this in SQL 2005

WITH [TEMPTABLENAME] AS
(SELECT ROW_NUMBER() OVER (PARTITION BY user ORDER BY loginout_datetime desc) AS ROWID, * FROM logtablename)
SELECT user,loginout_datetime FROM [TEMPTABLENAME] WHERE ROWID=1

Monday, March 12, 2012

MS SQL Dynamic stored procedure using a datetime variable

Hi I'm new to MS SQL and trying to write a very small dynamic stored procedure which is giving me a headache.

What I have is:

CREATE PROCEDURE busy_report

@.TableName varchar(255),
@.reporteddate datetime=NULL

AS
if @.reporteddate is null
select @.reporteddate = CURRENT_TIMESTAMP

-- Create a variable @.SQLStatement
DECLARE @.SQLStatement varchar(255)
SET DATEFORMAT dmy

-- Enter the dynamic SQL statement into the
-- variable @.SQLStatement
SELECT @.SQLStatement = "SELECT vendor, reporteddate, count(vendor) FROM " +
@.TableName + "WHERE reporteddate = ' "
+ @.reporteddate + " '"

-- Execute the SQL statement
EXEC(@.SQLStatement)
GO

The error I keep getting is:

Server: Msg 8114, Level 16, State 4, Procedure busy_report, Line 0
Error converting data type varchar to datetime.

Any ideas appreciated.

(Edit:)

I've also tried it this way:

CREATE PROCEDURE UK_busy_report

@.TableName varchar(255),
@.reporteddate datetime=NULL

AS

-- Create a variable @.SQLStatement
DECLARE @.SQLStatement varchar(255)
SELECT @.reporteddate=CONVERT(datetime, @.reporteddate)
IF @.@.ERROR <> 0 BEGIN

/* Do some error processing */

PRINT 'Error Occured' END

ELSE
-- Enter the dynamic SQL statement into the
-- variable @.SQLStatement
SELECT @.SQLStatement = "SELECT vendor, reporteddate, count(vendor) FROM " +
@.TableName + "WHERE reporteddate = ' "
+ @.reporteddate + " '"

-- Execute the SQL statement
EXEC(@.SQLStatement)
GO

Which gives me the same error!

.logic.Ahhh...the smell of Oracle....

CREATE PROCEDURE busy_report
@.TableName varchar(255)
, @.reporteddate datetime=NULL
AS
BEGIN
DECLARE @.SQLStatement varchar(255)

IF @.reporteddate IS NULL
SELECT @.reporteddate = GetDate()

SELECT @.SQLStatement = 'SELECT vendor, reporteddate, count(vendor) FROM '
+ @.TableName + 'WHERE reporteddate = '
+ ''''
+ @.reporteddate
+ ''''

EXEC(@.SQLStatement)
END
GO

It's been a while

If you want specifc date formats look up CONVERT in Books Online (BOL)|||It gives you the same error because it occurs on the last concatenation of @.SQLStatement.

"WHERE reporteddate = '" + convert(char(10), @.reporteddate, 101) + "'"|||Originally posted by rdjabarov
It gives you the same error because it occurs on the last concatenation of @.SQLStatement.

"WHERE reporteddate = '" + convert(char(10), @.reporteddate, 101) + "'"

Yeah...you're definetley going to need to worry about conversion...

What's the column reporteddate defined as?|||Originally posted by Brett Kaiser
Yeah...you're definetley going to need to worry about conversion...

What's the column reporteddate defined as?

Hi, the column is a smalldatetime type.

With your solution Brett I' getting a Server: Msg 295, Level 16, State 3, Procedure UK_busy_report, Line 11
Syntax error converting character string to smalldatetime data type.

Using:

CREATE PROCEDURE UK_busy_report
@.TableName varchar(255)
, @.reporteddate smalldatetime=NULL
AS
BEGIN
DECLARE @.SQLStatement varchar(255)

IF @.reporteddate IS NULL
SELECT @.reporteddate = GetDate()

SELECT @.SQLStatement = 'SELECT vendor, reporteddate, count(vendor) FROM '
+ @.TableName + 'WHERE reporteddate = '
+ ''''
+ @.reporteddate
+ ''''

EXEC(@.SQLStatement)
END
GO

I've also tried to convert it to nvarchar as follows:

CREATE PROCEDURE UK_busy_report
@.TableName varchar(255)
, @.reporteddate smalldatetime=NULL
AS
BEGIN
DECLARE @.SQLStatement varchar(255)

IF @.reporteddate IS NULL
SELECT @.reporteddate = GetDate()

SELECT @.SQLStatement = 'SELECT vendor, reporteddate, count(vendor) FROM '
+ @.TableName + 'WHERE reporteddate = '
+ ''''
+ convert (nvarchar(14), @.reporteddate, 101)
+ ''''

EXEC(@.SQLStatement)
END
GO

And I get: Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '='.

I think this conversion is the way to go but not sure of exact syntax. I'll keep checking through BOL and if anyone has any more ideas they'd be greatly appreciated :)

.logic.|||I've again altered it to:

CREATE PROCEDURE UK_busy_report
@.TableName varchar(255)
, @.reporteddate varchar(40)
AS
BEGIN
DECLARE @.SQLStatement varchar(255)
DECLARE @.date datetime


SELECT @.reporteddate=CONVERT(datetime, @.date, 103)
IF @.@.ERROR <> 0

BEGIN
Print 'ERROR'
END

ELSE

SELECT @.SQLStatement = 'SELECT vendor, reporteddate, count(vendor) FROM '
+ @.TableName + 'WHERE reporteddate = '
+ ''''
+ convert (nvarchar(14), @.reporteddate, 101)
+ ''''

EXEC(@.SQLStatement)
END
GO

I'm running it with: exec UK_busy_report EU_master_week6, '02/02/04';

And it seems to be running fine but it doesn't return any info, even though I know that date exists in the table.