Friday, March 30, 2012
Reading a text file from a stored procedure.
Is there a simple way to do this ?
Thanks in advance to all who reply !Not with ANSI-92 syntax. You'd have to use specific DBMS extensions for it. Pick the engine (Oracle, SQL Server, UDB, etc.) and post accordingly.|||I am using SQL Server 7.0.
I know how to do this in Oracle using the DBMS functions. Are there similar functions in MSSQL ?
Thanks for your reply !|||I use sp_OAxxx with FileSystemObject.|||Originally posted by BrutusBuckeye
I am using SQL Server 7.0.
I know how to do this in Oracle using the DBMS functions. Are there similar functions in MSSQL ?
Thanks for your reply ! In my opinion, this is one of the fundamental design flaws in Oracle. They are attempting to make PL/SQL a programming language instead of a data[base] manipulation language.
If you stop and think about it, reading text the way that you want to do it is a client side activity. Using BCP or BULK INSERT are server side activities. There is a fundamental difference between them (which machine the code actually runs on)!
Any solution you find for MS-SQL will involve server side activity. Sybase (now Microsoft) never intended for Transact-SQL scripts to run on the client, they always assumed that those Transact-SQL scripts would run on the server. That is exactly why user interface code, file access, etc are absent from Transact-SQL... The absence is by design.
Using Microsoft Transact-SQL, you'll need to either adopt a server centric point of view, or write your client side code using the client language. There is a clear distinction between the client and server in Transact-SQL.
-PatP|||BrutusBuckeye, Pat has a very strong opinion about all this ;)
I'd still use sp_OAxxx if you insist on reading a text file one line at a time, but why bother? Use BULK INSERT and then deal with it in a recordset-based fashion!|||UNCLE !!!! :)
Thanks for all your help. I am indeed going the Bulk Insert route.
Thanks again from the school of hard knocks.. :)|||Originally posted by rdjabarov
BrutusBuckeye, Pat has a very strong opinion about all this ;) Dang! Did I let that secret out again ?!?!
-PatP
Reading a long string
How can i see what a long string value is? I have a stored procedure which
creates a dynamic xml string and when i select it at the end of the SP the
result is about 100 chars long although i know it is about 7000 long and I
need to inspect the whole string, put it in an xml reader interface etc to
play around with. Even if i send the result to file, it is still truncated.
How can I read the whole string?
thanksWhat version of SQL are you using? XML data needs an XML client.
In SQL 2005 there's a built-in reader, that can display the XML in humanly
readable form, but for SQL 2000 you'd need a client application - look into
using SQLXML.
ML
http://milambda.blogspot.com/|||"louise raisbeck" <louiseraisbeck@.discussions.microsoft.com> wrote in
message news:B8A6F36D-818D-44AB-A992-95744A9E1056@.microsoft.com...
> Hi there,
> How can i see what a long string value is? I have a stored procedure which
> creates a dynamic xml string and when i select it at the end of the SP the
> result is about 100 chars long although i know it is about 7000 long and I
> need to inspect the whole string, put it in an xml reader interface etc to
> play around with. Even if i send the result to file, it is still
> truncated.
> How can I read the whole string?
> thanks
If this is SQL 2k and you are using Query Analyser, ensure that you have
set your results length long enough.
Look at Tools->Options Choose Results tab, then put 8000 in the box for
Maximum Characters Per Column
Rick Sawtell
MCT, MCSD, MCDBA|||THANKS!!! i didnt realise you could set this option.
In response to ML - I am creating my own custom xml string. I wont go into
reasons but in a nutshell it is completely dynamic, not as simple as return
this resultset as xml. I then use that as an xml datasource in a .net page.
Regards
"Rick Sawtell" wrote:
> "louise raisbeck" <louiseraisbeck@.discussions.microsoft.com> wrote in
> message news:B8A6F36D-818D-44AB-A992-95744A9E1056@.microsoft.com...
> If this is SQL 2k and you are using Query Analyser, ensure that you have
> set your results length long enough.
> Look at Tools->Options Choose Results tab, then put 8000 in the box for
> Maximum Characters Per Column
>
> Rick Sawtell
> MCT, MCSD, MCDBA
>
>
re-adding a removed extended stored procedure
I have recently remove few extended stored procedure on a sql server 2000
sp4 as part of our sql lockdown, including 'xp_getnetname'. When I try to
schedule a DTS job, it get the following error msg:
"Cannot find the function xp_getnetname in the library 'xplog70.dll'. Reason
127"...
I have added xp_getnetname (successfully!) using:
EXEC sp_addextendedproc 'xp_getnetname' ,'xplog70.dll'
BUT i still get the same error message. I am ABLE to use "sp_helptext
xp_getnetname" which gives me "xplog70.dll" as the output but I don't know
why I cannot execute it.
Thanks
"I saw it work in a cartoon once so I am pretty sure I can do it."Found the problem, the SP is in the xpstar.dll
--
Senior DBA
MSc in CS, MCSE4, IBM Certified MQ 5.3 Administrator
"I saw it work in a cartoon once so I am pretty sure I can do it."
"Sas" wrote:
> Hi everyone,
> I have recently remove few extended stored procedure on a sql server 2000
> sp4 as part of our sql lockdown, including 'xp_getnetname'. When I try to
> schedule a DTS job, it get the following error msg:
> "Cannot find the function xp_getnetname in the library 'xplog70.dll'. Reas
on
> 127"...
> I have added xp_getnetname (successfully!) using:
> EXEC sp_addextendedproc 'xp_getnetname' ,'xplog70.dll'
> BUT i still get the same error message. I am ABLE to use "sp_helptext
> xp_getnetname" which gives me "xplog70.dll" as the output but I don't know
> why I cannot execute it.
> Thanks
> --
> "I saw it work in a cartoon once so I am pretty sure I can do it."
Wednesday, March 28, 2012
read usergroup for a username with stored procedure
Hi
I wounder if there is a sp in the master db that can give me what usergroup a username is connected to / and or give me info if the username is valid (Windows NT login).
If not: then how do I read what usergroup a username is connected to? sysxlogin table in master db? And can I connect to a sp in master db from another db? Can I create a sp in my db that reads in the master db?
Thanks!!
Best Regards
Staffan
Yes, sp_helpuser
As long as your login has privileges to run system procedures in the master database, you will be able to run the procedure from any database (SQL Server always checks the master database if the procedure starts with sp_ )
sqlRead Uncommitted
We add :
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
to the stored procedure and the blocking has gone down and I'm addressing a
similar problem with other stored procedures. I know the whole "dirty read"
thing and I'm not sure how likely that is...but is there anything else we
should be aware of while using this statement?
Thanks
Apart from the obvious, doing dirty read you risk getting inconsistent data:
You can get false data corruption messages. Like reading the data while "physically" in flux. Just
don't worry about them. If you see them, and want to handle it, just re-try.
Also, if on 2005, consider using any of the snapshot isolation modes. But make sure you read up on
the consequences first.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:5DEC3C93-73F8-4F24-B264-2018B423C8F4@.microsoft.com...
> Stored procedure is causing blocking. Stored procedure only reads.
> We add :
> SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
> to the stored procedure and the blocking has gone down and I'm addressing a
> similar problem with other stored procedures. I know the whole "dirty read"
> thing and I'm not sure how likely that is...but is there anything else we
> should be aware of while using this statement?
> Thanks
|||See http://sqlblogcasts.com/blogs/tonyrogerson/archive/2006/11/10/1280.aspx
..
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:5DEC3C93-73F8-4F24-B264-2018B423C8F4@.microsoft.com...
> Stored procedure is causing blocking. Stored procedure only reads.
> We add :
> SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
> to the stored procedure and the blocking has gone down and I'm addressing
> a
> similar problem with other stored procedures. I know the whole "dirty
> read"
> thing and I'm not sure how likely that is...but is there anything else we
> should be aware of while using this statement?
> Thanks
sql
Read Uncommitted
We add :
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
to the stored procedure and the blocking has gone down and I'm addressing a
similar problem with other stored procedures. I know the whole "dirty read"
thing and I'm not sure how likely that is...but is there anything else we
should be aware of while using this statement?
ThanksApart from the obvious, doing dirty read you risk getting inconsistent data:
You can get false data corruption messages. Like reading the data while "physically" in flux. Just
don't worry about them. If you see them, and want to handle it, just re-try.
Also, if on 2005, consider using any of the snapshot isolation modes. But make sure you read up on
the consequences first.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:5DEC3C93-73F8-4F24-B264-2018B423C8F4@.microsoft.com...
> Stored procedure is causing blocking. Stored procedure only reads.
> We add :
> SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
> to the stored procedure and the blocking has gone down and I'm addressing a
> similar problem with other stored procedures. I know the whole "dirty read"
> thing and I'm not sure how likely that is...but is there anything else we
> should be aware of while using this statement?
> Thanks|||See http://sqlblogcasts.com/blogs/tonyrogerson/archive/2006/11/10/1280.aspx
.
--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:5DEC3C93-73F8-4F24-B264-2018B423C8F4@.microsoft.com...
> Stored procedure is causing blocking. Stored procedure only reads.
> We add :
> SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
> to the stored procedure and the blocking has gone down and I'm addressing
> a
> similar problem with other stored procedures. I know the whole "dirty
> read"
> thing and I'm not sure how likely that is...but is there anything else we
> should be aware of while using this statement?
> Thanks
Read Uncommitted
We add :
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
to the stored procedure and the blocking has gone down and I'm addressing a
similar problem with other stored procedures. I know the whole "dirty read"
thing and I'm not sure how likely that is...but is there anything else we
should be aware of while using this statement?
ThanksApart from the obvious, doing dirty read you risk getting inconsistent data:
You can get false data corruption messages. Like reading the data while "phy
sically" in flux. Just
don't worry about them. If you see them, and want to handle it, just re-try.
Also, if on 2005, consider using any of the snapshot isolation modes. But ma
ke sure you read up on
the consequences first.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:5DEC3C93-73F8-4F24-B264-2018B423C8F4@.microsoft.com...
> Stored procedure is causing blocking. Stored procedure only reads.
> We add :
> SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
> to the stored procedure and the blocking has gone down and I'm addressing
a
> similar problem with other stored procedures. I know the whole "dirty rea
d"
> thing and I'm not sure how likely that is...but is there anything else we
> should be aware of while using this statement?
> Thanks|||See http://sqlblogcasts.com/blogs/tonyr...11/10/1280.aspx
.
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)
"jason7655" <jason7655@.discussions.microsoft.com> wrote in message
news:5DEC3C93-73F8-4F24-B264-2018B423C8F4@.microsoft.com...
> Stored procedure is causing blocking. Stored procedure only reads.
> We add :
> SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
> to the stored procedure and the blocking has gone down and I'm addressing
> a
> similar problem with other stored procedures. I know the whole "dirty
> read"
> thing and I'm not sure how likely that is...but is there anything else we
> should be aware of while using this statement?
> Thanks
Monday, March 26, 2012
Read Text file from SqlServer
Hi Frinds,
I have the text file in my server.
Is it possible to read the text file and insert into table via sql server stored procedure.
yes. You can use BCP or BULK INSERT to do the job. Refer to Books Online for more details. http://search.live.com/macros/sql_server_user_education/booksonlineread only Stored Procedures?
modify the SP?
Yes, just don't give users who shouldn't be to change procedures permissions
to do so. If it is an existing problem, remove the relevant users from the
sysadmin, db_owner and db_ddladmin roles. Then you can either REVOKE or DENY
the CREATE PROCEDURE statement to the users.
Jacco Schalkwijk
SQL Server MVP
"J Jetson" <JJetson@.discussions.microsoft.com> wrote in message
news:638520E1-FB4D-4960-8345-56A174249A45@.microsoft.com...
> Is there a way to make Stored Procedures "read only" or make it so no one
> can
> modify the SP?
sql
read only Stored Procedures?
modify the SP?Yes, just don't give users who shouldn't be to change procedures permissions
to do so. If it is an existing problem, remove the relevant users from the
sysadmin, db_owner and db_ddladmin roles. Then you can either REVOKE or DENY
the CREATE PROCEDURE statement to the users.
--
Jacco Schalkwijk
SQL Server MVP
"J Jetson" <JJetson@.discussions.microsoft.com> wrote in message
news:638520E1-FB4D-4960-8345-56A174249A45@.microsoft.com...
> Is there a way to make Stored Procedures "read only" or make it so no one
> can
> modify the SP?
read only database performance question
a read-only database, and about 2 minutes when the database is not
read-only.
Details:
SQL Server 7
The stored proc exists on a writable database on the same server. It stuffs
a subset of about 20000 rows into a temp table and repeatedly updates the
temp table while doing selects and joins on the read only database, for
example,
Select *
into #LocalTempTable
from SAMESERVER.dbo.ReadOnlyDatabaseTable
Update tmp set tmp.SomeColumn = 1
from #LocalTempTable tmp
inner join SAMESERVER.dbo.ReadOnlyDatabaseTable x on
tmp.ID = x.ID
where SomeCriteria = SomeValue, etc, etc.
If I change the read-only database to writable it works fine. There are no
explicit transactions used in the stored proc. On the same server, a
production database exists and is constantly using transactions and temp
tables, but I wouldn't think this is an overall server performance issue
because it handles the same load when the suspect database is not read-only.
Any thoughts will be greatly appreciated. I'm searching all over and can't
seem to find reference to this type of issue."Bruce Hendry" <bruce@.binya.com> wrote in message
news:yNf2e.3954$oy3.2375@.newssvr30.news.prodigy.co m...
> In a nutshell, I have a stored proc that takes appx 15 minutes when it
> uses a read-only database, and about 2 minutes when the database is not
> read-only.
> Details:
> SQL Server 7
> The stored proc exists on a writable database on the same server. It
> stuffs a subset of about 20000 rows into a temp table and repeatedly
> updates the temp table while doing selects and joins on the read only
> database, for example,
> Select *
> into #LocalTempTable
> from SAMESERVER.dbo.ReadOnlyDatabaseTable
> Update tmp set tmp.SomeColumn = 1
> from #LocalTempTable tmp
> inner join SAMESERVER.dbo.ReadOnlyDatabaseTable x on
> tmp.ID = x.ID
> where SomeCriteria = SomeValue, etc, etc.
> If I change the read-only database to writable it works fine. There are
> no explicit transactions used in the stored proc. On the same server, a
> production database exists and is constantly using transactions and temp
> tables, but I wouldn't think this is an overall server performance issue
> because it handles the same load when the suspect database is not
> read-only.
> Any thoughts will be greatly appreciated. I'm searching all over and
> can't seem to find reference to this type of issue.
I don't know, but the usual advice would be to use Profiler and/or Query
Analyzer to trace the procedure execution and view the execution plan, to
see exactly what's taking so long.
To take a complete guess, in the writable database, MSSQL is adding
statistics dynamically to the table to improve performance. Although the
execution times are very different, and I'm not really convinced that
missing statistics could make such a difference. You might also put an index
on #LocalTempTable(ID) if you haven't already.
Simon
Friday, March 23, 2012
Read Only Access to Stored Procedures
organization for the "production" environment. The programmers get
DataReader/DataWriter access in production, however, they are wanting
read-only access to the stored procedures.
Does anyone know of a why to give them READ ONLY access to stored procedures
?
Thanks for your help.
ColetteThe only permissions you can grant Users WRT SP's is Execute.
Either a user is allowed to execute a SP or not.
I would seriously re-consider Developer Access to production. Developers
should only be in development, and support staff read only production rights
.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Colette" wrote:
> We do not allow anyone except DBA's the DBO access permission in our
> organization for the "production" environment. The programmers get
> DataReader/DataWriter access in production, however, they are wanting
> read-only access to the stored procedures.
> Does anyone know of a why to give them READ ONLY access to stored procedur
es?
> Thanks for your help.
> Colette
Read information from transaction log
I am a beginner in SQL/RDBMS and learning the different nuances of the SQL
Server. I know that all activities in a database are stored in a transaction
log and I can see where the file is stored. My question is how do I read any
information from a transaction log?
For example I delete a row manually in the Enterprise Manager (which I
should not have deleted), how do I Rollback that delete or how do I read the
transaction log to see what has happened and reverse that action.
Any help will be highly appreciated.
Thanks in advance
Aditya.There isn't a documented method to read transaction log data. You can get
some info by using undocumented commands like DBCC LOG. A better method is
with a third party tool like Lumigent's Log Explorer www.lumigent.com.
quote:
> For example I delete a row manually in the Enterprise Manager (which I
> should not have deleted), how do I Rollback that delete or how do I read
the
quote:
> transaction log to see what has happened and reverse that action.
If you are running in the FULL or BULK_LOGGED recovery model, you can backup
the current transaction log, restore the database (to a different name if
you want to keep the existing database intact) and then apply your
transaction log backups up to the point of the delete. See the Books Online
for more information.
Hope this helps.
Dan Guzman
SQL Server MVP
"Aditya" <grafica@.md2.vsnl.net.in> wrote in message
news:O2CkJSq4DHA.2888@.tk2msftngp13.phx.gbl...
quote:
> Hi,
> I am a beginner in SQL/RDBMS and learning the different nuances of the SQL
> Server. I know that all activities in a database are stored in a
transaction
quote:
> log and I can see where the file is stored. My question is how do I read
any
quote:
> information from a transaction log?
> For example I delete a row manually in the Enterprise Manager (which I
> should not have deleted), how do I Rollback that delete or how do I read
the
quote:|||Hi Aditya
> transaction log to see what has happened and reverse that action.
> Any help will be highly appreciated.
> Thanks in advance
> Aditya.
>
Dan answered your question about reading the log.
For rollback, there is no way to do it from Enterprise Manager. Each insert,
update and delete is auto-committed.
The only alternative is to use a query tool like query analyzer, and use a
BEGIN TRANSACTION before any changes, and then if you're satisified with the
change you can COMMIT TRANSACTION, if you're not, you can ROLLBACK
TRANSACTION.
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"Aditya" <grafica@.md2.vsnl.net.in> wrote in message
news:O2CkJSq4DHA.2888@.tk2msftngp13.phx.gbl...
quote:
> Hi,
> I am a beginner in SQL/RDBMS and learning the different nuances of the SQL
> Server. I know that all activities in a database are stored in a
transaction
quote:
> log and I can see where the file is stored. My question is how do I read
any
quote:
> information from a transaction log?
> For example I delete a row manually in the Enterprise Manager (which I
> should not have deleted), how do I Rollback that delete or how do I read
the
quote:|||Just to comment on both Dan and Kalen's posts, Log Explorer will allow you
> transaction log to see what has happened and reverse that action.
> Any help will be highly appreciated.
> Thanks in advance
> Aditya.
>
to generate SQL commands to redo or undo a specific transaction. That comes
in handy sometimes when developers have direct access to production
databases.
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
CareerBuilder.com
"Aditya" <grafica@.md2.vsnl.net.in> wrote in message
news:O2CkJSq4DHA.2888@.tk2msftngp13.phx.gbl...
quote:
> Hi,
> I am a beginner in SQL/RDBMS and learning the different nuances of the SQL
> Server. I know that all activities in a database are stored in a
transaction
quote:
> log and I can see where the file is stored. My question is how do I read
any
quote:
> information from a transaction log?
> For example I delete a row manually in the Enterprise Manager (which I
> should not have deleted), how do I Rollback that delete or how do I read
the
quote:|||Hi,
> transaction log to see what has happened and reverse that action.
> Any help will be highly appreciated.
> Thanks in advance
> Aditya.
>
Thank you all for your posts. I will try them and get back if I have any
other queries.
Thanks again.
Aditya.
"Aditya" <grafica@.md2.vsnl.net.in> wrote in message
news:O2CkJSq4DHA.2888@.tk2msftngp13.phx.gbl...
quote:
> Hi,
> I am a beginner in SQL/RDBMS and learning the different nuances of the SQL
> Server. I know that all activities in a database are stored in a
transaction
quote:
> log and I can see where the file is stored. My question is how do I read
any
quote:
> information from a transaction log?
> For example I delete a row manually in the Enterprise Manager (which I
> should not have deleted), how do I Rollback that delete or how do I read
the
quote:|||There is also LogPi: http://www.logpi.com/
> transaction log to see what has happened and reverse that action.
> Any help will be highly appreciated.
> Thanks in advance
> Aditya.
>
--
Mike Epprecht, Microsoft SQL Server MVP
Epprecht Consulting (PTY) LTD
Johannesburg, South Africa
Mobile: +27-82-552-0268
IM: mike@.NOSPAMepprecht.net
Specialist SQL Server Solutions and Consulting
"Aditya" <grafica@.md2.vsnl.net.in> wrote in message
news:%23KzpPsz4DHA.2696@.TK2MSFTNGP09.phx.gbl...
quote:|||Hi,
> Hi,
> Thank you all for your posts. I will try them and get back if I have any
> other queries.
> Thanks again.
> Aditya.
> "Aditya" <grafica@.md2.vsnl.net.in> wrote in message
> news:O2CkJSq4DHA.2888@.tk2msftngp13.phx.gbl...
SQL[QUOTE]
> transaction
> any
> the
>
Still I like to known the internal format from the transactionlog. I can't
find it on the internet.
Greetz.
"Mike Epprecht [SQL Server MVP]" <mike@.NOSPAMepprecht.net> wrote in message
news:uVhuhO64DHA.2496@.TK2MSFTNGP09.phx.gbl...
quote:|||It is not published. Possibly, if you sign such an agreement that these
> There is also LogPi: http://www.logpi.com/
> --
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Epprecht Consulting (PTY) LTD
> Johannesburg, South Africa
> Mobile: +27-82-552-0268
> IM: mike@.NOSPAMepprecht.net
> Specialist SQL Server Solutions and Consulting
> "Aditya" <grafica@.md2.vsnl.net.in> wrote in message
> news:%23KzpPsz4DHA.2696@.TK2MSFTNGP09.phx.gbl...
> SQL
read[QUOTE]
read[QUOTE]
>
vendors has signed with MS, you can get your hands on it. Assuming that such
an agreement does exists for the structure of the t-log, of course. These
vendors might have reverse-engineered the log structure the hard way.
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=...ublic.sqlserver
"Renegade" <Nospam-123-123@.hotmail.com> wrote in message
news:40180e6c$0$333$e4fe514c@.news.xs4all.nl...
quote:sql
> Hi,
> Still I like to known the internal format from the transactionlog. I can't
> find it on the internet.
> Greetz.
>
Read information from transaction log
I am a beginner in SQL/RDBMS and learning the different nuances of the SQL
Server. I know that all activities in a database are stored in a transaction
log and I can see where the file is stored. My question is how do I read any
information from a transaction log?
For example I delete a row manually in the Enterprise Manager (which I
should not have deleted), how do I Rollback that delete or how do I read the
transaction log to see what has happened and reverse that action.
Any help will be highly appreciated.
Thanks in advance
Aditya.There isn't a documented method to read transaction log data. You can get
some info by using undocumented commands like DBCC LOG. A better method is
with a third party tool like Lumigent's Log Explorer www.lumigent.com.
> For example I delete a row manually in the Enterprise Manager (which I
> should not have deleted), how do I Rollback that delete or how do I read
the
> transaction log to see what has happened and reverse that action.
If you are running in the FULL or BULK_LOGGED recovery model, you can backup
the current transaction log, restore the database (to a different name if
you want to keep the existing database intact) and then apply your
transaction log backups up to the point of the delete. See the Books Online
for more information.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Aditya" <grafica@.md2.vsnl.net.in> wrote in message
news:O2CkJSq4DHA.2888@.tk2msftngp13.phx.gbl...
> Hi,
> I am a beginner in SQL/RDBMS and learning the different nuances of the SQL
> Server. I know that all activities in a database are stored in a
transaction
> log and I can see where the file is stored. My question is how do I read
any
> information from a transaction log?
> For example I delete a row manually in the Enterprise Manager (which I
> should not have deleted), how do I Rollback that delete or how do I read
the
> transaction log to see what has happened and reverse that action.
> Any help will be highly appreciated.
> Thanks in advance
> Aditya.
>|||Hi Aditya
Dan answered your question about reading the log.
For rollback, there is no way to do it from Enterprise Manager. Each insert,
update and delete is auto-committed.
The only alternative is to use a query tool like query analyzer, and use a
BEGIN TRANSACTION before any changes, and then if you're satisified with the
change you can COMMIT TRANSACTION, if you're not, you can ROLLBACK
TRANSACTION.
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"Aditya" <grafica@.md2.vsnl.net.in> wrote in message
news:O2CkJSq4DHA.2888@.tk2msftngp13.phx.gbl...
> Hi,
> I am a beginner in SQL/RDBMS and learning the different nuances of the SQL
> Server. I know that all activities in a database are stored in a
transaction
> log and I can see where the file is stored. My question is how do I read
any
> information from a transaction log?
> For example I delete a row manually in the Enterprise Manager (which I
> should not have deleted), how do I Rollback that delete or how do I read
the
> transaction log to see what has happened and reverse that action.
> Any help will be highly appreciated.
> Thanks in advance
> Aditya.
>|||Just to comment on both Dan and Kalen's posts, Log Explorer will allow you
to generate SQL commands to redo or undo a specific transaction. That comes
in handy sometimes when developers have direct access to production
databases. :)
--
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
CareerBuilder.com
"Aditya" <grafica@.md2.vsnl.net.in> wrote in message
news:O2CkJSq4DHA.2888@.tk2msftngp13.phx.gbl...
> Hi,
> I am a beginner in SQL/RDBMS and learning the different nuances of the SQL
> Server. I know that all activities in a database are stored in a
transaction
> log and I can see where the file is stored. My question is how do I read
any
> information from a transaction log?
> For example I delete a row manually in the Enterprise Manager (which I
> should not have deleted), how do I Rollback that delete or how do I read
the
> transaction log to see what has happened and reverse that action.
> Any help will be highly appreciated.
> Thanks in advance
> Aditya.
>|||Hi,
Thank you all for your posts. I will try them and get back if I have any
other queries.
Thanks again.
Aditya.
"Aditya" <grafica@.md2.vsnl.net.in> wrote in message
news:O2CkJSq4DHA.2888@.tk2msftngp13.phx.gbl...
> Hi,
> I am a beginner in SQL/RDBMS and learning the different nuances of the SQL
> Server. I know that all activities in a database are stored in a
transaction
> log and I can see where the file is stored. My question is how do I read
any
> information from a transaction log?
> For example I delete a row manually in the Enterprise Manager (which I
> should not have deleted), how do I Rollback that delete or how do I read
the
> transaction log to see what has happened and reverse that action.
> Any help will be highly appreciated.
> Thanks in advance
> Aditya.
>|||There is also LogPi: http://www.logpi.com/
--
--
Mike Epprecht, Microsoft SQL Server MVP
Epprecht Consulting (PTY) LTD
Johannesburg, South Africa
Mobile: +27-82-552-0268
IM: mike@.NOSPAMepprecht.net
Specialist SQL Server Solutions and Consulting
"Aditya" <grafica@.md2.vsnl.net.in> wrote in message
news:%23KzpPsz4DHA.2696@.TK2MSFTNGP09.phx.gbl...
> Hi,
> Thank you all for your posts. I will try them and get back if I have any
> other queries.
> Thanks again.
> Aditya.
> "Aditya" <grafica@.md2.vsnl.net.in> wrote in message
> news:O2CkJSq4DHA.2888@.tk2msftngp13.phx.gbl...
> > Hi,
> >
> > I am a beginner in SQL/RDBMS and learning the different nuances of the
SQL
> > Server. I know that all activities in a database are stored in a
> transaction
> > log and I can see where the file is stored. My question is how do I read
> any
> > information from a transaction log?
> >
> > For example I delete a row manually in the Enterprise Manager (which I
> > should not have deleted), how do I Rollback that delete or how do I read
> the
> > transaction log to see what has happened and reverse that action.
> >
> > Any help will be highly appreciated.
> >
> > Thanks in advance
> > Aditya.
> >
> >
>|||Hi,
Still I like to known the internal format from the transactionlog. I can't
find it on the internet.
Greetz.
"Mike Epprecht [SQL Server MVP]" <mike@.NOSPAMepprecht.net> wrote in message
news:uVhuhO64DHA.2496@.TK2MSFTNGP09.phx.gbl...
> There is also LogPi: http://www.logpi.com/
> --
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Epprecht Consulting (PTY) LTD
> Johannesburg, South Africa
> Mobile: +27-82-552-0268
> IM: mike@.NOSPAMepprecht.net
> Specialist SQL Server Solutions and Consulting
> "Aditya" <grafica@.md2.vsnl.net.in> wrote in message
> news:%23KzpPsz4DHA.2696@.TK2MSFTNGP09.phx.gbl...
> > Hi,
> >
> > Thank you all for your posts. I will try them and get back if I have any
> > other queries.
> >
> > Thanks again.
> > Aditya.
> >
> > "Aditya" <grafica@.md2.vsnl.net.in> wrote in message
> > news:O2CkJSq4DHA.2888@.tk2msftngp13.phx.gbl...
> > > Hi,
> > >
> > > I am a beginner in SQL/RDBMS and learning the different nuances of the
> SQL
> > > Server. I know that all activities in a database are stored in a
> > transaction
> > > log and I can see where the file is stored. My question is how do I
read
> > any
> > > information from a transaction log?
> > >
> > > For example I delete a row manually in the Enterprise Manager (which I
> > > should not have deleted), how do I Rollback that delete or how do I
read
> > the
> > > transaction log to see what has happened and reverse that action.
> > >
> > > Any help will be highly appreciated.
> > >
> > > Thanks in advance
> > > Aditya.
> > >
> > >
> >
> >
>|||It is not published. Possibly, if you sign such an agreement that these
vendors has signed with MS, you can get your hands on it. Assuming that such
an agreement does exists for the structure of the t-log, of course. These
vendors might have reverse-engineered the log structure the hard way.
--
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Renegade" <Nospam-123-123@.hotmail.com> wrote in message
news:40180e6c$0$333$e4fe514c@.news.xs4all.nl...
> Hi,
> Still I like to known the internal format from the transactionlog. I can't
> find it on the internet.
> Greetz.
>
read from .ini file
i have a requirement in which i need to read from a .ini file in the stored procedure of sql server 2K.
is it possible? i tried searching on google but i cannot find anything that can help.At the very least you should be able to use the Scripting.FileSystemObject and instantiate it use sp_OACreate (see SQL BOL for details).
However, I'm not sure that this is such a great idea. You're mixing environments (database and operating system) and the results may not be all that you would like them to be. How often is the .ini file going to be updated? Would it be possible to store the .ini values in the db (or even replace the .ini file with a database parameters table)?
Regards,
hmscott
Wednesday, March 21, 2012
READ COMMITTED SNAPSHOT ON causes performance degradation
stored procedure with different parameters. This stored procedures does only
SELECT. There are no other activity on the database.
The stored procedure containst this select
SELECT Model,AVG(Price),MIN(Price),MAX(Price),COUNT(*)
FROM SH_Product
WHERE Project_Number = @.Station
AND EmployeeID = 0
AND Type = @.Match100
GROUP BY Model
ORDER BY Model
When the database is set in READ COMMITTED SNAPSHOT OFF mode, the number of
transactions per second increases linearly as more and more connections are
added.
But when the database is set to READ COMMITTED SNAPSHOT ON, the performance
degrades after 20 users, the total transactions processed per second remains
constant when number of users increase. That means for each user the
transactions per second reduces.
I can understand this if there was any other INSERT/UPDATE/DELETE activity
happening on the database, as SELECT will have to traverse the row version
chain to get the data, but in SELECT only environment, how can the
performance degrade.
With READ COMMITTED SNAPSHOT ON, there are no locks to acquire hence less
overhead for SQL Server. I have a PSS ticket open for this, but I am getting
a satisfactory answer. All I get is since SELECT needs to go to tempdb to get
row version it is slower, but my point is if there is no data change why does
SQL Server has to go to tempdb?
Am I missing something?. Please help.
Thank youOn Thu, 27 Sep 2007 12:31:01 -0700, Shailesh Khanal wrote:
(snip)
>I can understand this if there was any other INSERT/UPDATE/DELETE activity
>happening on the database, as SELECT will have to traverse the row version
>chain to get the data, but in SELECT only environment, how can the
>performance degrade.
>With READ COMMITTED SNAPSHOT ON, there are no locks to acquire hence less
>overhead for SQL Server. I have a PSS ticket open for this, but I am getting
>a satisfactory answer. All I get is since SELECT needs to go to tempdb to get
>row version it is slower, but my point is if there is no data change why does
>SQL Server has to go to tempdb?
Hi Shailesh,
I'm not intimately familiar with the internals of READ COMMITTED
SNAPSHOT, but my guess is that SQL Server has to go to tempdb because it
can't know that there are no previous row versions there without looking
first.
Have you considered setting the database to READ ONLY? That will fully
eliminate all locking overhead.
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis|||Thanks Hugo
I am seeing this behavior while running a benchmark, which has different
sets of tests, one of them being CPU intensive test which only does SELECT.
It is not on a real production database so putting database in READ ONLY
mode is not an issue, but I wanted to understand the performance issue
without doing it.
I looked at page file structure in Kalen Delaney's book and I don't see any
information about whether SQL server puts a status bit on the page itself
for locked rows. But with READ COMMITTED SNAPSHOT ON, SQL server puts a 14
byte data in each row to store Transaction Sequence number (XSN), it is only
added when the row is updated. So logically speaking when a connection tries
to SELECT from a row, it has a XSN and when it goes to check the row in disk
if there is no XSN field then it should immediately know that the row is not
modified and should not go to tempdb to check.
Even if there is XSN for the row, and if it's value is less than SELECT XSN
then it should check lock records before going to tempdb. And this overhead
is also incurred when database is in READ COMMITTED SNAPSHOT OFF mode. So I
don't really get why the performance suffers so much.
"Hugo Kornelis" <hugo@.perFact.REMOVETHIS.info.INVALID> wrote in message
news:m3oqf31go4ti3d37736nsegqp2patoqjin@.4ax.com...
> On Thu, 27 Sep 2007 12:31:01 -0700, Shailesh Khanal wrote:
> (snip)
>>I can understand this if there was any other INSERT/UPDATE/DELETE activity
>>happening on the database, as SELECT will have to traverse the row version
>>chain to get the data, but in SELECT only environment, how can the
>>performance degrade.
>>With READ COMMITTED SNAPSHOT ON, there are no locks to acquire hence less
>>overhead for SQL Server. I have a PSS ticket open for this, but I am
>>getting
>>a satisfactory answer. All I get is since SELECT needs to go to tempdb to
>>get
>>row version it is slower, but my point is if there is no data change why
>>does
>>SQL Server has to go to tempdb?
> Hi Shailesh,
> I'm not intimately familiar with the internals of READ COMMITTED
> SNAPSHOT, but my guess is that SQL Server has to go to tempdb because it
> can't know that there are no previous row versions there without looking
> first.
> Have you considered setting the database to READ ONLY? That will fully
> eliminate all locking overhead.
> --
> Hugo Kornelis, SQL Server MVP
> My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Read a Database Datetime (datatype) value and pass it into a Parameter
I'm running the following stored proceudre that I will eventually be using checboxes and a sqlDataAdapter to fill a DataGrid using VB.Net.
When I attempt to execute the SP on the server side for testing, it throws me the error "syntax error converting datetime from character string".
conversion of datatypes is something I'm still new to so I can't begin to understand how to write the code thus why I'm seeking help. Here's the SP Code:
As soon as it hits the @.CREATED as datetime =.... this is where it throws that error. Any idea on how to convert the datetime data type to a character string?
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTERPROCEDURE [dbo].[uspPvtSelectCommand]
@.MAC as varchar(18)='00:AC:12:E5:76:9C',
@.CREATED asdatetime='4/25/2007 8:40:50 AM',
@.MODIFIED asdatetime='5/19/2007 5:05:04 AM',
@.WORKSTATION_NAME as varchar(13)='B000E7FF53C72',
@.IP_ADDRESS as varchar(15)='171.136.201.142',
@.USER_NAME as varchar(8)='nbe5533',
@.OPERATING_SYSTEM as varchar(25)='Windows XP Professional',
@.SERVICE_PACK as varchar(3)='2.0',
@.BAND_VERSION as varchar(7)='5.06 b2',
@.WORKSTATION_OU as varchar(200)='CN=B001321D14A41,OU=Desktops,OU=Agents,OU=Card,OU=Customer Service and Support,OU=Utility,OU=NCG,OU=Workstations,OU=BAND,DC=corp,DC=bankofamerica,DC=com',
@.WORKSTATION_OWNER as varchar(200)='CN=Davis\, Wally NBE5533,OU=Distributed Server Support,OU=NCG Administrators,OU=Accounts,OU=BAND,DC=corp,DC=bankofamerica,DC=com',
@.MANUFACTURER as varchar(26)='Dell Computer Corporation;',
@.MODEL as varchar(40)='Latitude D600;',
@.CHASSIS as varchar(10)='8;12;',
@.SERIAL_NUMBER as varchar(30)='.83SFB51.CN486434737027.;',
@.PROCESSOR as varchar(100)='Intel(R) Pentium(R) M processor 1600MHz;',
@.HARD_DRIVE as varchar(40)='FUJITSU MHV2040AH;',
@.HARD_DRIVE_SIZE as varchar(30)='40007761920;',
@.MEMORY as varchar(22)='1073741824;1073741824;',
@.NAME as varchar(100)='KB887979',
@.VERSION as varchar(20)='VALUE DOES NOT EXIST',
@.BUILD as varchar(45)='1.3',
@.INSTALL_STATUS as varchar(20)='1',
@.INSTALL_DATE as varchar(21)='3/31/2005 2:40:34 PM',
@.PACKAGE_NAME as varchar(90)='CRYSTAL_REPORTS_ACTIVEX_VIEWER_10.0_9.2_8.6_8.5_20.05.08.01_WKS_XP2KNT_BAND_I1^EDE'
AS
-- SET NOCOUNT ON;
SELECT main.MAC, main.CREATED, main.MODIFIED, hardware.MANUFACTURER, hardware.MODEL, hardware.CHASSIS, hardware.SERIAL_NUMBER, hardware.PROCESSOR,
hardware.HARD_DRIVE, hardware.HARD_DRIVE_SIZE, hardware.MEMORY, network.WORKSTATION_NAME, network.IP_ADDRESS,
network.USER_NAME, network.OPERATING_SYSTEM, network.SERVICE_PACK, network.BAND_VERSION, network.WORKSTATION_OU,
network.WORKSTATION_OWNER, software.MAC, software.NAME, software.VERSION, software.BUILD, software.INSTALL_STATUS,
software.INSTALL_DATE, software.PACKAGE_NAME
FROM main INNERJOIN
hardware ON main.MAC = hardware.MAC INNERJOIN
network ON main.MAC = network.MAC INNERJOIN
software ON main.MAC = software.MAC
WHERE MAIN.MAC LIKE'%'+@.MAC+'%'AND MAIN.CREATED LIKE'%'+@.CREATED+'%'AND MAIN.MODIFIED LIKE'%'+@.MODIFIED+'%'AND NETWORK.WORKSTATION_NAME LIKE'%'+@.WORKSTATION_NAME+'%'AND NETWORK.IP_ADDRESS LIKE'%'+@.IP_ADDRESS+'%'AND NETWORK.USER_NAMELIKE'%'+@.USER_NAME+'%'AND NETWORK.OPERATING_SYSTEM LIKE'%'+@.OPERATING_SYSTEM+'%'AND NETWORK.SERVICE_PACK LIKE'%'+@.SERVICE_PACK+'%'AND NETWORK.BAND_VERSION LIKE'%'+@.BAND_VERSION+'%'AND NETWORK.WORKSTATION_OU LIKE'%'+@.WORKSTATION_OU+'%'AND NETWORK.WORKSTATION_OWNER LIKE'%'+@.WORKSTATION_OWNER+'%'AND HARDWARE.MANUFACTURER LIKE'%'+@.MANUFACTURER+'%'AND HARDWARE.MODEL LIKE'%'+@.MODEL+'%'AND HARDWARE.CHASSIS LIKE'%'+@.CHASSIS+'%'AND HARDWARE.SERIAL_NUMBER LIKE'%'+@.SERIAL_NUMBER+'%'AND HARDWARE.PROCESSOR LIKE'%'+@.PROCESSOR+'%'AND HARDWARE.HARD_DRIVE LIKE'%'+@.HARD_DRIVE+'%'AND HARDWARE.HARD_DRIVE_SIZE LIKE'%'+@.HARD_DRIVE_SIZE+'%'AND HARDWARE.MEMORY LIKE'%'+@.MEMORY+'%'AND SOFTWARE.NAME LIKE'%'+@.NAME+'%'AND SOFTWARE.VERSION LIKE'%'+@.VERSION+'%'AND SOFTWARE.BUILD LIKE'%'+@.BUILD+'%'AND SOFTWARE.INSTALL_STATUS LIKE'%'+@.INSTALL_STATUS+'%'AND SOFTWARE.INSTALL_DATE LIKE'%'+@.INSTALL_DATE+'%'AND SOFTWARE.PACKAGE_NAME LIKE'%'+@.PACKAGE_NAME+'%'
Thank you,
Wallace
hi, this is because you were concatenating a datetime variable with a string '%'change this lines on your where clause
--AND MAIN.CREATED LIKE '%'+@.CREATED+'%'
AND MAIN.CREATED = @.CREATED
--AND MAIN.MODIFIED LIKE '%'+@.MODIFIED+'%'
AND MAIN.MODIFIED = @.MODIFIED|||
CREATED LIKE '%'+@.CREATED+'%'
Wallace,
I guess that I am at a loss about why you are concatenating wildcards to a datetime value.
Is there a particular problem you are attempting to solve by so doing?
Without converstion, you cannot add characters ( '%' ) to a datetime datatype. (What exactly do you hope to accomplish by adding '%' to the datetime?)
I am assuming that Main.Created is a datetime datetype.
In fact, I wonder if any of the above parameters really need to have '%' added to each side of the value...
|||As soon as it hits the @.CREATED as datetime =.... this is where it throws that error. Any idea on how to convert the datetime data type to a character string?
Are you doing this like to compare parts of dates? Like:
drop table dateRow
go
create table dateRow
(
dateValue datetime
)
insert into dateRow
select '20070101'
union all
select '20070201'
union all
select '20070301'
union all
select '20070401'
union all
select '20070501'
union all
select '20070601'
go
--find rows from 2007
select *
from dateRow
where convert(varchar(8),datevalue,112) like '2007_'
go
--find rows from January
select *
from dateRow
where convert(varchar(8),datevalue,112) like '_01__'
--find rows from June
select *
from dateRow
where convert(varchar(8),datevalue,112) like '_06__'
Interesting idea...Probably not perfect in terms of performance. A better way to do this involves having a table of dates that you can join to your date value (if you don't have time values.) Then you can index the month, year, or day values for fast searching.
Here is an article with technique to load the date table: http://drsql.spaces.live.com/blog/cns!80677FB08B3162E4!1349.entry
|||This doesn't cause any errors on my server...
Code Snippet
CREATE PROCEDURE dbo.uspPvtSelectCommand
( @.CREATED as datetime = '4/25/2007 8:40:50 AM',
@.MODIFIED as datetime = '5/19/2007 5:05:04 AM'
)
AS
SELECT getdate(), @.Created, @.Modified
GO
I think the error comes from the concatenation of the datetime parameter as I indicated earlier.
LIKE '%'+@.CREATED+'%' AND MAIN.MODIFIED LIKE '%'+@.MODIFIED+'%'
The following fails with such an error...
Code Snippet
ALTER PROCEDURE dbo.uspPvtSelectCommand
( @.CREATED as datetime = '4/25/2007 8:40:50 AM',
@.MODIFIED as datetime = '5/19/2007 5:05:04 AM'
)
AS
SELECT getdate(), @.Created, ( '%' +@.Modified + '%' )
GO
EXECUTE dbo.uspPvtSelectCommand
Server: Msg 241, Level 16, State 1, Procedure uspPvtSelectCommand, Line 6
Conversion failed when converting datetime from character string.
Hi Arnie,
I figured I would give everyone who's been so kind to help with a little more information. I have a DataGrid in my vb.net app.
I have 25 fields/columns and when I go to click on "Preview" from the DataGrid, it hit's the second field parameter "CREATED" and throws the error, " Enter a value for parameter "CREATED". What I have are a bunch of checkboxes on my form, so that our Managers can click on any combination of checkboxs (that represents a field in one of 4 tables), it will pull up only those checkboxex (fields) of that data, use the SP to join those fields and then store it in the datagrid and then a separate sub-routine that exports it to Excel. So, right now, when I go back to recreate a new SQLDataAdapter in vb.net, when I select the stored procedure, it doesn't see the list of parameters, but, it is connected to the right db server so, the problem seems to be the way my Stored procedure is written.
I have since removed the concatenation and changed it so that MAIN.CREATED = @.CREATED AND MAIN.MODIFIED = @.MODIFIED but still the error.
Any further assistance would be appreciated. Here is what the SP looks like now.
USE platform_validation_tool
GO
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTERPROCEDURE [dbo].[uspPvtSelectCommand]
@.MAC as varchar(18),
@.CREATED asdatetime,
@.MODIFIED asdatetime,
@.WORKSTATION_NAME as varchar(13),
@.IP_ADDRESS as varchar(15),
@.USER_NAME as varchar(8),
@.OPERATING_SYSTEM as varchar(25),
@.SERVICE_PACK as varchar(3),
@.BAND_VERSION as varchar(7),
@.WORKSTATION_OU as varchar(200),
@.WORKSTATION_OWNER as varchar(200),
@.MANUFACTURER as varchar(26),
@.MODEL as varchar(40),
@.CHASSIS as varchar(10),
@.SERIAL_NUMBER as varchar(30),
@.PROCESSOR as varchar(100),
@.HARD_DRIVE as varchar(40),
@.HARD_DRIVE_SIZE as varchar(30),
@.MEMORY as varchar(22),
@.NAME as varchar(100),
@.VERSION as varchar(20),
@.BUILD as varchar(45),
@.INSTALL_STATUS as varchar(20),
@.INSTALL_DATE as varchar(21),
@.PACKAGE_NAME as varchar(90)
AS
-- SET NOCOUNT ON;
SELECT main.MAC,getdate(), @.CREATED, @.MODIFIED, hardware.MANUFACTURER, hardware.MODEL, hardware.CHASSIS, hardware.SERIAL_NUMBER, hardware.PROCESSOR,
hardware.HARD_DRIVE, hardware.HARD_DRIVE_SIZE, hardware.MEMORY, network.WORKSTATION_NAME, network.IP_ADDRESS,
network.USER_NAME, network.OPERATING_SYSTEM, network.SERVICE_PACK, network.BAND_VERSION, network.WORKSTATION_OU,
network.WORKSTATION_OWNER, software.MAC, software.NAME, software.VERSION, software.BUILD, software.INSTALL_STATUS,
software.INSTALL_DATE, software.PACKAGE_NAME
FROM main INNERJOIN
hardware ON main.MAC = hardware.MAC INNERJOIN
network ON main.MAC = network.MAC INNERJOIN
software ON main.MAC = software.MAC
WHERE MAIN.MAC LIKE'%'+@.MAC+'%'AND MAIN.CREATED = @.CREATED AND MAIN.MODIFIED = @.MODIFIED AND NETWORK.WORKSTATION_NAME LIKE'%'+@.WORKSTATION_NAME+'%'AND NETWORK.IP_ADDRESS LIKE'%'+@.IP_ADDRESS+'%'AND NETWORK.USER_NAMELIKE'%'+@.USER_NAME+'%'AND NETWORK.OPERATING_SYSTEM LIKE'%'+@.OPERATING_SYSTEM+'%'AND NETWORK.SERVICE_PACK LIKE'%'+@.SERVICE_PACK+'%'AND NETWORK.BAND_VERSION LIKE'%'+@.BAND_VERSION+'%'AND NETWORK.WORKSTATION_OU LIKE'%'+@.WORKSTATION_OU+'%'AND NETWORK.WORKSTATION_OWNER LIKE'%'+@.WORKSTATION_OWNER+'%'AND HARDWARE.MANUFACTURER LIKE'%'+@.MANUFACTURER+'%'AND HARDWARE.MODEL LIKE'%'+@.MODEL+'%'AND HARDWARE.CHASSIS LIKE'%'+@.CHASSIS+'%'AND HARDWARE.SERIAL_NUMBER LIKE'%'+@.SERIAL_NUMBER+'%'AND HARDWARE.PROCESSOR LIKE'%'+@.PROCESSOR+'%'AND HARDWARE.HARD_DRIVE LIKE'%'+@.HARD_DRIVE+'%'AND HARDWARE.HARD_DRIVE_SIZE LIKE'%'+@.HARD_DRIVE_SIZE+'%'AND HARDWARE.MEMORY LIKE'%'+@.MEMORY+'%'AND SOFTWARE.NAME LIKE'%'+@.NAME+'%'AND SOFTWARE.VERSION LIKE'%'+@.VERSION+'%'AND SOFTWARE.BUILD LIKE'%'+@.BUILD+'%'AND SOFTWARE.INSTALL_STATUS LIKE'%'+@.INSTALL_STATUS+'%'AND SOFTWARE.INSTALL_DATE LIKE'%'+@.INSTALL_DATE+'%'AND SOFTWARE.PACKAGE_NAME LIKE'%'+@.PACKAGE_NAME+'%'
Thanks and Sincerely,
Wallace
|||Wallace,
I need you to clarify.
If I understand this correctly, you are passing into the stored procedure the checkbox values for each of the parameters listed. Is that correct?
And what checkboxes are checked determines what data is expected?
OR,
Is there actual values in the input parameters, AND the presence of a check indicated to use that value in the WHERE clause...
|||That's correct, I want to pass values, being read from the database, into the sql sp parameters, based on which checkboxes are checked.The values will be read from the Database, passed into the parameter, and joined via the SP into a DataGrid. I have a separate vb.net sub routine that will take all of this and export to excel.
Thanks,
Wally
|||I'm trying to understand and help, but I'm still confused. You replied "That's correct..." to two diametrically opposed questions.
Do you wish to collect multiple rows of data from the database and display that data in the DataGrid?
How do you determine what should be displayed?
Are all columns always returned and displayed?
Is this a search routine where you pass in some search criteria, hence the input parameters?
What is the application code that calls the stored procedure? (Please post.)
|||Arnie,
We have a database that has 4 tables, 25 columns of data to pull from. Software/Hardware data is pulled from the PC's and stored on this database.
The vb.net application I'm creating will connect to a database called "platform_validation_tool" running on SQL 2005, and
will use an SQLConnection, SQLDataAdapter and DataSet to mirror the tables.
Whether the user checks one checkbox or all 25, I want it to pull any column of data based on those checkboxes checked, i.e. using the SQLDataAdapter and it's methods, it will search the database, pass it into the input parameters, and then return it to the DataGrid for display. That is the first step. Right now, I can't get the stored procedure to work because of the datetime datatype to convert to a string. Once I can jump this hurdle, then I'll setup the rest of the code in vb.net. Here's some of the vb.net code that will allow me to retrieve the data from the database by identifying the specific SourceColumn and then Fill the DataGrid:
SqlDA_SinglePkgName.SelectCommand.Parameters.Item(1).Value = SourceColumn
SqlDA_SinglePkgName.SelectCommand.Parameters.Item(2).Value = SourceColumn
etc, and so on.,
SqlDA_SinglePkgName.Fill(WkstnAndSoftwareVerDS1.uspSelectAnyPkgName) --> This is the line of code that calls the stored procedure "uspSelectAnyPkgName".
Let me know if it needs further explanation. I've only been in programming for 3 months. Thank you for your patience.
Wally
|||hi,
i'm just curious on how did you present the values in your checkboxes? a.) is it along side on a data grid? or b.) does your checkbox has an input box along side it where the user can input a search string then ticks the checkbox if it should be included in the search?
if your doing b. does the user need to input the time for the created and modified date?|||How about posting some of the vb.net code that invokes the sp?
SQLDataSource definition, etc.|||
DaleJ,
My code is at work and until I return there, simplest way I can put it is the routine goes like this:
The checkboxes are just inside of a GroupBox on a separate Form and not imbedded within or next to the DataGrid.
If checkbox1.checked = True Then
SqlDA_SinglePkgName.SelectCommand.Parameters.Item(1).Value = SourceColumn
Else checkbox1.checked = False
End If
If checkbox2.checked = True Then
SqlDA_SinglePkgName.SelectCommand.Parameters.Item(2).Value = SourceColumn
Else checkbox2.checked = False Then
End If
Item(1), Item(2), item(3), etc. is the logical order of the column parameters, i.e. Item(0) = @.ReturnValue, Item(1) = @.MAC, Item(2) = @.CREATED, Item(3) = @.MODIFIED, etc.
There will be 25 checkboxes in all, from 4 tables. There's other code that I still need to plug in but this is the jist of it. I just can't get the stored procedure to input any of the data from the MODIFIED and CREATED columns in the database (using DateTime datatype) to convert over to a varchar string.
Finally, after the checkboxes have been evaluated as checked or unchecked, it will run the stored procedure on all the checkboxes whose boolean is True with the Fill method below .
SqlDA_SinglePkgName.Fill(WkstnAndSoftwareVerDS1.uspSelectAnyPkgName) --> This is the line of code that calls the stored procedure "uspSelectAnyPkgName" and fills the DataSet.
It may seem elementary but it's the easiest way for me to start out learning to code until I get a couple of vb.net classes under my belt.
Wallace
|||The following code example 'should' find a match for any parameters passed in by your users. If this works for you, I suspect that you could do away with the checkboxes on the form AND the IF-End IF blocks -they will not be needed. Just set all the parameters
Since you are starting out learning, I suggest that you quickly drop using all caps. We all have learned to read using mixed case and we recognize and read mixed case with greater ease than all caps. However, there is a 'tradition' of using caps for the SQL language words.
Also, rigorously following good formatting principles will make your code easier to read, and easier to maintain.
Code Snippet
ALTER PROCEDURE [dbo].[uspPvtSelectCommand]
( @.MAC varchar(18),
@.Created datetime,
@.Modified datetime,
@.Workstation_Name varchar(13),
@.IP_Address varchar(15),
@.User_Name varchar(8),
@.Operating_System varchar(25),
@.Service_Pack varchar(3),
@.Band_Version varchar(7),
@.Workstation_OU varchar(200),
@.Workstation_Owner varchar(200),
@.Manufacturer varchar(26),
@.Model varchar(40),
@.Chassis varchar(10),
@.Serial_Number varchar(30),
@.Processor varchar(100),
@.Hard_Drive varchar(40),
@.Hard_Drive_Size varchar(30),
@.Memory varchar(22),
@.Name varchar(100),
@.Version varchar(20),
@.Build varchar(45),
@.Install_Status varchar(20),
@.Install_Date varchar(21),
@.Package_Name varchar(90)
)
AS
SET NOCOUNT ON;
SELECT
m.MAC,
getdate(),
m.Created,
m.Modified,
h.Manufacturer,
h.Model,
h.Chassis,
h.Serial_Number,
h.Processor,
h.Hard_Drive,
h.Hard_Drive_Size,
h.Memory,
n.Workstation_Name,
n.IP_Address,
n.[User_Name],
n.Operating_System,
n.Service_Pack,
n.Band_Version,
n.Workstation_OU,
n.Workstation_Owner,
s.MAC,
s.[Name],
s.Version,
s.Build,
s.Install_Status,
s.Install_Date,
s.Package_Name
FROM Main m
JOIN Hardware h
ON m.MAC = h.MAC
JOIN Network n
ON m.MAC = n.MAC
JOIN Software s
ON m.MAC = s.MAC
WHERE ( m.MAC = @.MAC
AND m.Created = coalesce( nullif( @.Created, 0 ), m.Created )
AND m.Modified = coalesce( nullif( @.Modified, 0 ), m.Modified )
AND n.Workstation_Name = coalesce( nullif( @.Workstation_Name, '' ), n.Workstation_Name )
AND n.IP_Address = coalesce( nullif( @.IP_Address, '' ), n.IP_Address )
AND n.[User_Name] = coalesce( nullif( @.User_Name, '' ), n.[User_Name] )
AND n.Operating_System = coalesce( nullif( @.Operating_System, '' ), n.Operating_System )
AND n.Service_Pack = coalesce( nullif( @.Service_Pack, '' ), n.Service_Pack )
AND n.Band_Version = coalesce( nullif( @.Band_Version, '' ), n.Band_Version )
AND n.Workstation_OU = coalesce( nullif( @.Workstation_OU, '' ), n.Workstation_OU )
AND n.Workstation_Owner = coalesce( nullif( @.Workstation_Owner, '' ), n.Workstation_Owner )
AND h.Manufacturer = coalesce( nullif( @.Manufacturer, '' ), h.Manufacturer )
AND h.Model = coalesce( nullif( @.Model, '' ), h.Model )
AND h.Chassis = coalesce( nullif( @.Chassis, '' ), h.Chassis )
AND h.Serial_Number = coalesce( nullif( @.Serial_Number, '' ), h.Serial_Number )
AND h.Processor = coalesce( nullif( @.Processor, '' ), h.Processor )
AND h.Hard_Drive = coalesce( nullif( @.Hard_Drive, '' ), h.Hard_Drive )
AND h.Hard_Drive_Size = coalesce( nullif( @.Hard_Drive_Size, '' ), h.Hard_Drive_Size )
AND h.Memory = coalesce( nullif( @.Memory, '' ), h.Memory )
AND s.[Name] = coalesce( nullif( @.Name, '' ), s.[Name] )
AND s.Version = coalesce( nullif( @.Version, '' ), s.Version )
AND s.Build = coalesce( nullif( @.Build, '' ), s.Build )
AND s.Install_Status = coalesce( nullif( @.Install_Status, '' ), s.Install_Status )
AND s.Install_Date = coalesce( nullif( @.Install_Date, '' ), s.Install_Date )
AND s.Package_Name = coalesce( nullif( @.Package_Name, '' ), s.Package_Name )
GO
|||Hey Arnie,
Thank you for the tips. I'll be sure to apply them as a newcomer.
The code you supplied me for the @.CREATED and @.MODIFIED parameters didn't create any errors when I Executed the stored procedure. I went into the datagrid on my vb.net form, clicked on the preview button, and again, it threw me the error, "Enter a value for paramter "CREATED". What I did then was added two dates (format is > 04/04/2007) in the datagrid "value" fields to see what it would return. The results it returned are as follows: Type = Int32, Value = 0. It looks as if it reads the data I inputted into the datagrid value field it recognizes this date format as an Integer but somehow didn't return this data in the results window.
Now, when it hit the 4th line, where I started adding the code you updated, "AND n.Workstation_Name = coalesce( nullif( @.Workstation_Name, '' ), n.Workstation_Name )", in the WHERE clause, it threw this error:
Msg 306, Level 16, State 1, Procedure uspPvtSelectCommand, Line 34
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
The bottom line is that the stored procedure will not read the date and time info from the CREATED or the MODIFIED fields in the main.MAC table. This is the format in the database for both fields -> 4/25/2007 5:05:04 AM
I'm still trying to find some material on converting this date and time string value to a datetime datatype value.
Any other suggestions are most welcome.
Wally
Read a Database Datetime (datatype) value and pass it into a Parameter
I'm running the following stored proceudre that I will eventually be using checboxes and a sqlDataAdapter to fill a DataGrid using VB.Net.
When I attempt to execute the SP on the server side for testing, it throws me the error "syntax error converting datetime from character string".
conversion of datatypes is something I'm still new to so I can't begin to understand how to write the code thus why I'm seeking help. Here's the SP Code:
As soon as it hits the @.CREATED as datetime =.... this is where it throws that error. Any idea on how to convert the datetime data type to a character string?
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[uspPvtSelectCommand]
@.MAC as varchar(18) = '00:AC:12:E5:76:9C',
@.CREATED as datetime = '4/25/2007 8:40:50 AM',
@.MODIFIED as datetime = '5/19/2007 5:05:04 AM',
@.WORKSTATION_NAME as varchar(13) = 'B000E7FF53C72',
@.IP_ADDRESS as varchar(15) = '171.136.201.142',
@.USER_NAME as varchar(8) = 'nbe5533',
@.OPERATING_SYSTEM as varchar(25) = 'Windows XP Professional',
@.SERVICE_PACK as varchar(3) = '2.0',
@.BAND_VERSION as varchar(7) = '5.06 b2',
@.WORKSTATION_OU as varchar(200) = 'CN=B001321D14A41,OU=Desktops,OU=Agents,OU=Card,OU=Customer Service and Support,OU=Utility,OU=NCG,OU=Workstations,OU=BAND,DC=corp,DC=bankofamerica,DC=com',
@.WORKSTATION_OWNER as varchar(200) = 'CN=Davis\, Wally NBE5533,OU=Distributed Server Support,OU=NCG Administrators,OU=Accounts,OU=BAND,DC=corp,DC=bankofamerica,DC=com',
@.MANUFACTURER as varchar(26) = 'Dell Computer Corporation;',
@.MODEL as varchar(40) = 'Latitude D600;',
@.CHASSIS as varchar(10) = '8;12;',
@.SERIAL_NUMBER as varchar(30) = '.83SFB51.CN486434737027.;',
@.PROCESSOR as varchar(100) = 'Intel(R) Pentium(R) M processor 1600MHz;',
@.HARD_DRIVE as varchar(40) = 'FUJITSU MHV2040AH;',
@.HARD_DRIVE_SIZE as varchar(30) = '40007761920;',
@.MEMORY as varchar(22) = '1073741824;1073741824;',
@.NAME as varchar(100) = 'KB887979',
@.VERSION as varchar(20) = 'VALUE DOES NOT EXIST',
@.BUILD as varchar(45) = '1.3',
@.INSTALL_STATUS as varchar(20) = '1',
@.INSTALL_DATE as varchar(21) = '3/31/2005 2:40:34 PM' ,
@.PACKAGE_NAME as varchar(90) = 'CRYSTAL_REPORTS_ACTIVEX_VIEWER_10.0_9.2_8.6_8.5_20.05.08.01_WKS_XP2KNT_BAND_I1^EDE'
AS
-- SET NOCOUNT ON;
SELECT main.MAC, main.CREATED, main.MODIFIED, hardware.MANUFACTURER, hardware.MODEL, hardware.CHASSIS, hardware.SERIAL_NUMBER, hardware.PROCESSOR,
hardware.HARD_DRIVE, hardware.HARD_DRIVE_SIZE, hardware.MEMORY, network.WORKSTATION_NAME, network.IP_ADDRESS,
network.USER_NAME, network.OPERATING_SYSTEM, network.SERVICE_PACK, network.BAND_VERSION, network.WORKSTATION_OU,
network.WORKSTATION_OWNER, software.MAC, software.NAME, software.VERSION, software.BUILD, software.INSTALL_STATUS,
software.INSTALL_DATE, software.PACKAGE_NAME
FROM main INNER JOIN
hardware ON main.MAC = hardware.MAC INNER JOIN
network ON main.MAC = network.MAC INNER JOIN
software ON main.MAC = software.MAC
WHERE MAIN.MAC LIKE '%'+@.MAC+'%' AND MAIN.CREATED LIKE '%'+@.CREATED+'%' AND MAIN.MODIFIED LIKE '%'+@.MODIFIED+'%' AND NETWORK.WORKSTATION_NAME LIKE '%'+@.WORKSTATION_NAME+'%' AND NETWORK.IP_ADDRESS LIKE '%'+@.IP_ADDRESS+'%' AND NETWORK.USER_NAME LIKE '%'+@.USER_NAME+'%' AND NETWORK.OPERATING_SYSTEM LIKE '%'+@.OPERATING_SYSTEM+'%' AND NETWORK.SERVICE_PACK LIKE '%'+@.SERVICE_PACK+'%' AND NETWORK.BAND_VERSION LIKE '%'+@.BAND_VERSION+'%' AND NETWORK.WORKSTATION_OU LIKE '%'+@.WORKSTATION_OU+'%' AND NETWORK.WORKSTATION_OWNER LIKE '%'+@.WORKSTATION_OWNER+'%' AND HARDWARE.MANUFACTURER LIKE '%'+@.MANUFACTURER+'%' AND HARDWARE.MODEL LIKE '%'+@.MODEL+'%' AND HARDWARE.CHASSIS LIKE '%'+@.CHASSIS+'%' AND HARDWARE.SERIAL_NUMBER LIKE '%'+@.SERIAL_NUMBER+'%' AND HARDWARE.PROCESSOR LIKE '%'+@.PROCESSOR+'%' AND HARDWARE.HARD_DRIVE LIKE '%'+@.HARD_DRIVE+'%' AND HARDWARE.HARD_DRIVE_SIZE LIKE '%'+@.HARD_DRIVE_SIZE+'%' AND HARDWARE.MEMORY LIKE '%'+@.MEMORY+'%' AND SOFTWARE.NAME LIKE '%'+@.NAME+'%' AND SOFTWARE.VERSION LIKE '%'+@.VERSION+'%' AND SOFTWARE.BUILD LIKE '%'+@.BUILD+'%' AND SOFTWARE.INSTALL_STATUS LIKE '%'+@.INSTALL_STATUS+'%' AND SOFTWARE.INSTALL_DATE LIKE '%'+@.INSTALL_DATE+'%' AND SOFTWARE.PACKAGE_NAME LIKE '%'+@.PACKAGE_NAME+'%'
Thank you,
Wallace
hi, this is because you were concatenating a datetime variable with a string '%'change this lines on your where clause
--AND MAIN.CREATED LIKE '%'+@.CREATED+'%'
AND MAIN.CREATED = @.CREATED
--AND MAIN.MODIFIED LIKE '%'+@.MODIFIED+'%'
AND MAIN.MODIFIED = @.MODIFIED|||
CREATED LIKE '%'+@.CREATED+'%'
Wallace,
I guess that I am at a loss about why you are concatenating wildcards to a datetime value.
Is there a particular problem you are attempting to solve by so doing?
Without converstion, you cannot add characters ( '%' ) to a datetime datatype. (What exactly do you hope to accomplish by adding '%' to the datetime?)
I am assuming that Main.Created is a datetime datetype.
In fact, I wonder if any of the above parameters really need to have '%' added to each side of the value...
|||As soon as it hits the @.CREATED as datetime =.... this is where it throws that error. Any idea on how to convert the datetime data type to a character string?
Are you doing this like to compare parts of dates? Like:
drop table dateRow
go
create table dateRow
(
dateValue datetime
)
insert into dateRow
select '20070101'
union all
select '20070201'
union all
select '20070301'
union all
select '20070401'
union all
select '20070501'
union all
select '20070601'
go
--find rows from 2007
select *
from dateRow
where convert(varchar(8),datevalue,112) like '2007_'
go
--find rows from January
select *
from dateRow
where convert(varchar(8),datevalue,112) like '_01__'
--find rows from June
select *
from dateRow
where convert(varchar(8),datevalue,112) like '_06__'
Interesting idea...Probably not perfect in terms of performance. A better way to do this involves having a table of dates that you can join to your date value (if you don't have time values.) Then you can index the month, year, or day values for fast searching.
Here is an article with technique to load the date table: http://drsql.spaces.live.com/blog/cns!80677FB08B3162E4!1349.entry
|||This doesn't cause any errors on my server...
Code Snippet
CREATE PROCEDURE dbo.uspPvtSelectCommand
( @.CREATED as datetime = '4/25/2007 8:40:50 AM',
@.MODIFIED as datetime = '5/19/2007 5:05:04 AM'
)
AS
SELECT getdate(), @.Created, @.Modified
GO
I think the error comes from the concatenation of the datetime parameter as I indicated earlier.
LIKE '%'+@.CREATED+'%' AND MAIN.MODIFIED LIKE '%'+@.MODIFIED+'%'
The following fails with such an error...
Code Snippet
ALTER PROCEDURE dbo.uspPvtSelectCommand
( @.CREATED as datetime = '4/25/2007 8:40:50 AM',
@.MODIFIED as datetime = '5/19/2007 5:05:04 AM'
)
AS
SELECT getdate(), @.Created, ( '%' +@.Modified + '%' )
GO
EXECUTE dbo.uspPvtSelectCommand
Server: Msg 241, Level 16, State 1, Procedure uspPvtSelectCommand, Line 6
Conversion failed when converting datetime from character string.
Hi Arnie,
I figured I would give everyone who's been so kind to help with a little more information. I have a DataGrid in my vb.net app.
I have 25 fields/columns and when I go to click on "Preview" from the DataGrid, it hit's the second field parameter "CREATED" and throws the error, " Enter a value for parameter "CREATED". What I have are a bunch of checkboxes on my form, so that our Managers can click on any combination of checkboxs (that represents a field in one of 4 tables), it will pull up only those checkboxex (fields) of that data, use the SP to join those fields and then store it in the datagrid and then a separate sub-routine that exports it to Excel. So, right now, when I go back to recreate a new SQLDataAdapter in vb.net, when I select the stored procedure, it doesn't see the list of parameters, but, it is connected to the right db server so, the problem seems to be the way my Stored procedure is written.
I have since removed the concatenation and changed it so that MAIN.CREATED = @.CREATED AND MAIN.MODIFIED = @.MODIFIED but still the error.
Any further assistance would be appreciated. Here is what the SP looks like now.
USE platform_validation_tool
GO
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[uspPvtSelectCommand]
@.MAC as varchar(18),
@.CREATED as datetime,
@.MODIFIED as datetime,
@.WORKSTATION_NAME as varchar(13),
@.IP_ADDRESS as varchar(15),
@.USER_NAME as varchar(8),
@.OPERATING_SYSTEM as varchar(25),
@.SERVICE_PACK as varchar(3),
@.BAND_VERSION as varchar(7),
@.WORKSTATION_OU as varchar(200),
@.WORKSTATION_OWNER as varchar(200),
@.MANUFACTURER as varchar(26),
@.MODEL as varchar(40),
@.CHASSIS as varchar(10),
@.SERIAL_NUMBER as varchar(30),
@.PROCESSOR as varchar(100),
@.HARD_DRIVE as varchar(40),
@.HARD_DRIVE_SIZE as varchar(30),
@.MEMORY as varchar(22),
@.NAME as varchar(100),
@.VERSION as varchar(20),
@.BUILD as varchar(45),
@.INSTALL_STATUS as varchar(20),
@.INSTALL_DATE as varchar(21),
@.PACKAGE_NAME as varchar(90)
AS
-- SET NOCOUNT ON;
SELECT main.MAC, getdate(), @.CREATED, @.MODIFIED, hardware.MANUFACTURER, hardware.MODEL, hardware.CHASSIS, hardware.SERIAL_NUMBER, hardware.PROCESSOR,
hardware.HARD_DRIVE, hardware.HARD_DRIVE_SIZE, hardware.MEMORY, network.WORKSTATION_NAME, network.IP_ADDRESS,
network.USER_NAME, network.OPERATING_SYSTEM, network.SERVICE_PACK, network.BAND_VERSION, network.WORKSTATION_OU,
network.WORKSTATION_OWNER, software.MAC, software.NAME, software.VERSION, software.BUILD, software.INSTALL_STATUS,
software.INSTALL_DATE, software.PACKAGE_NAME
FROM main INNER JOIN
hardware ON main.MAC = hardware.MAC INNER JOIN
network ON main.MAC = network.MAC INNER JOIN
software ON main.MAC = software.MAC
WHERE MAIN.MAC LIKE '%'+@.MAC+'%' AND MAIN.CREATED = @.CREATED AND MAIN.MODIFIED = @.MODIFIED AND NETWORK.WORKSTATION_NAME LIKE '%'+@.WORKSTATION_NAME+'%' AND NETWORK.IP_ADDRESS LIKE '%'+@.IP_ADDRESS+'%' AND NETWORK.USER_NAME LIKE '%'+@.USER_NAME+'%' AND NETWORK.OPERATING_SYSTEM LIKE '%'+@.OPERATING_SYSTEM+'%' AND NETWORK.SERVICE_PACK LIKE '%'+@.SERVICE_PACK+'%' AND NETWORK.BAND_VERSION LIKE '%'+@.BAND_VERSION+'%' AND NETWORK.WORKSTATION_OU LIKE '%'+@.WORKSTATION_OU+'%' AND NETWORK.WORKSTATION_OWNER LIKE '%'+@.WORKSTATION_OWNER+'%' AND HARDWARE.MANUFACTURER LIKE '%'+@.MANUFACTURER+'%' AND HARDWARE.MODEL LIKE '%'+@.MODEL+'%' AND HARDWARE.CHASSIS LIKE '%'+@.CHASSIS+'%' AND HARDWARE.SERIAL_NUMBER LIKE '%'+@.SERIAL_NUMBER+'%' AND HARDWARE.PROCESSOR LIKE '%'+@.PROCESSOR+'%' AND HARDWARE.HARD_DRIVE LIKE '%'+@.HARD_DRIVE+'%' AND HARDWARE.HARD_DRIVE_SIZE LIKE '%'+@.HARD_DRIVE_SIZE+'%' AND HARDWARE.MEMORY LIKE '%'+@.MEMORY+'%' AND SOFTWARE.NAME LIKE '%'+@.NAME+'%' AND SOFTWARE.VERSION LIKE '%'+@.VERSION+'%' AND SOFTWARE.BUILD LIKE '%'+@.BUILD+'%' AND SOFTWARE.INSTALL_STATUS LIKE '%'+@.INSTALL_STATUS+'%' AND SOFTWARE.INSTALL_DATE LIKE '%'+@.INSTALL_DATE+'%' AND SOFTWARE.PACKAGE_NAME LIKE '%'+@.PACKAGE_NAME+'%'
Thanks and Sincerely,
Wallace
|||Wallace,
I need you to clarify.
If I understand this correctly, you are passing into the stored procedure the checkbox values for each of the parameters listed. Is that correct?
And what checkboxes are checked determines what data is expected?
OR,
Is there actual values in the input parameters, AND the presence of a check indicated to use that value in the WHERE clause...
|||That's correct, I want to pass values, being read from the database, into the sql sp parameters, based on which checkboxes are checked.The values will be read from the Database, passed into the parameter, and joined via the SP into a DataGrid. I have a separate vb.net sub routine that will take all of this and export to excel.
Thanks,
Wally
|||I'm trying to understand and help, but I'm still confused. You replied "That's correct..." to two diametrically opposed questions.
Do you wish to collect multiple rows of data from the database and display that data in the DataGrid?
How do you determine what should be displayed?
Are all columns always returned and displayed?
Is this a search routine where you pass in some search criteria, hence the input parameters?
What is the application code that calls the stored procedure? (Please post.)
|||Arnie,
We have a database that has 4 tables, 25 columns of data to pull from. Software/Hardware data is pulled from the PC's and stored on this database.
The vb.net application I'm creating will connect to a database called "platform_validation_tool" running on SQL 2005, and
will use an SQLConnection, SQLDataAdapter and DataSet to mirror the tables.
Whether the user checks one checkbox or all 25, I want it to pull any column of data based on those checkboxes checked, i.e. using the SQLDataAdapter and it's methods, it will search the database, pass it into the input parameters, and then return it to the DataGrid for display. That is the first step. Right now, I can't get the stored procedure to work because of the datetime datatype to convert to a string. Once I can jump this hurdle, then I'll setup the rest of the code in vb.net. Here's some of the vb.net code that will allow me to retrieve the data from the database by identifying the specific SourceColumn and then Fill the DataGrid:
SqlDA_SinglePkgName.SelectCommand.Parameters.Item(1).Value = SourceColumn
SqlDA_SinglePkgName.SelectCommand.Parameters.Item(2).Value = SourceColumn
etc, and so on.,
SqlDA_SinglePkgName.Fill(WkstnAndSoftwareVerDS1.uspSelectAnyPkgName) --> This is the line of code that calls the stored procedure "uspSelectAnyPkgName".
Let me know if it needs further explanation. I've only been in programming for 3 months. Thank you for your patience.
Wally
|||hi,
i'm just curious on how did you present the values in your checkboxes? a.) is it along side on a data grid? or b.) does your checkbox has an input box along side it where the user can input a search string then ticks the checkbox if it should be included in the search?
if your doing b. does the user need to input the time for the created and modified date?|||How about posting some of the vb.net code that invokes the sp?
SQLDataSource definition, etc.|||
DaleJ,
My code is at work and until I return there, simplest way I can put it is the routine goes like this:
The checkboxes are just inside of a GroupBox on a separate Form and not imbedded within or next to the DataGrid.
If checkbox1.checked = True Then
SqlDA_SinglePkgName.SelectCommand.Parameters.Item(1).Value = SourceColumn
Else checkbox1.checked = False
End If
If checkbox2.checked = True Then
SqlDA_SinglePkgName.SelectCommand.Parameters.Item(2).Value = SourceColumn
Else checkbox2.checked = False Then
End If
Item(1), Item(2), item(3), etc. is the logical order of the column parameters, i.e. Item(0) = @.ReturnValue, Item(1) = @.MAC, Item(2) = @.CREATED, Item(3) = @.MODIFIED, etc.
There will be 25 checkboxes in all, from 4 tables. There's other code that I still need to plug in but this is the jist of it. I just can't get the stored procedure to input any of the data from the MODIFIED and CREATED columns in the database (using DateTime datatype) to convert over to a varchar string.
Finally, after the checkboxes have been evaluated as checked or unchecked, it will run the stored procedure on all the checkboxes whose boolean is True with the Fill method below .
SqlDA_SinglePkgName.Fill(WkstnAndSoftwareVerDS1.uspSelectAnyPkgName) --> This is the line of code that calls the stored procedure "uspSelectAnyPkgName" and fills the DataSet.
It may seem elementary but it's the easiest way for me to start out learning to code until I get a couple of vb.net classes under my belt.
Wallace
|||The following code example 'should' find a match for any parameters passed in by your users. If this works for you, I suspect that you could do away with the checkboxes on the form AND the IF-End IF blocks -they will not be needed. Just set all the parameters
Since you are starting out learning, I suggest that you quickly drop using all caps. We all have learned to read using mixed case and we recognize and read mixed case with greater ease than all caps. However, there is a 'tradition' of using caps for the SQL language words.
Also, rigorously following good formatting principles will make your code easier to read, and easier to maintain.
Code Snippet
ALTER PROCEDURE [dbo].[uspPvtSelectCommand]
( @.MAC varchar(18),
@.Created datetime,
@.Modified datetime,
@.Workstation_Name varchar(13),
@.IP_Address varchar(15),
@.User_Name varchar(8),
@.Operating_System varchar(25),
@.Service_Pack varchar(3),
@.Band_Version varchar(7),
@.Workstation_OU varchar(200),
@.Workstation_Owner varchar(200),
@.Manufacturer varchar(26),
@.Model varchar(40),
@.Chassis varchar(10),
@.Serial_Number varchar(30),
@.Processor varchar(100),
@.Hard_Drive varchar(40),
@.Hard_Drive_Size varchar(30),
@.Memory varchar(22),
@.Name varchar(100),
@.Version varchar(20),
@.Build varchar(45),
@.Install_Status varchar(20),
@.Install_Date varchar(21),
@.Package_Name varchar(90)
)
AS
SET NOCOUNT ON;
SELECT
m.MAC,
getdate(),
m.Created,
m.Modified,
h.Manufacturer,
h.Model,
h.Chassis,
h.Serial_Number,
h.Processor,
h.Hard_Drive,
h.Hard_Drive_Size,
h.Memory,
n.Workstation_Name,
n.IP_Address,
n.[User_Name],
n.Operating_System,
n.Service_Pack,
n.Band_Version,
n.Workstation_OU,
n.Workstation_Owner,
s.MAC,
s.[Name],
s.Version,
s.Build,
s.Install_Status,
s.Install_Date,
s.Package_Name
FROM Main m
JOIN Hardware h
ON m.MAC = h.MAC
JOIN Network n
ON m.MAC = n.MAC
JOIN Software s
ON m.MAC = s.MAC
WHERE ( m.MAC = @.MAC
AND m.Created = coalesce( nullif( @.Created, 0 ), m.Created )
AND m.Modified = coalesce( nullif( @.Modified, 0 ), m.Modified )
AND n.Workstation_Name = coalesce( nullif( @.Workstation_Name, '' ), n.Workstation_Name )
AND n.IP_Address = coalesce( nullif( @.IP_Address, '' ), n.IP_Address )
AND n.[User_Name] = coalesce( nullif( @.User_Name, '' ), n.[User_Name] )
AND n.Operating_System = coalesce( nullif( @.Operating_System, '' ), n.Operating_System )
AND n.Service_Pack = coalesce( nullif( @.Service_Pack, '' ), n.Service_Pack )
AND n.Band_Version = coalesce( nullif( @.Band_Version, '' ), n.Band_Version )
AND n.Workstation_OU = coalesce( nullif( @.Workstation_OU, '' ), n.Workstation_OU )
AND n.Workstation_Owner = coalesce( nullif( @.Workstation_Owner, '' ), n.Workstation_Owner )
AND h.Manufacturer = coalesce( nullif( @.Manufacturer, '' ), h.Manufacturer )
AND h.Model = coalesce( nullif( @.Model, '' ), h.Model )
AND h.Chassis = coalesce( nullif( @.Chassis, '' ), h.Chassis )
AND h.Serial_Number = coalesce( nullif( @.Serial_Number, '' ), h.Serial_Number )
AND h.Processor = coalesce( nullif( @.Processor, '' ), h.Processor )
AND h.Hard_Drive = coalesce( nullif( @.Hard_Drive, '' ), h.Hard_Drive )
AND h.Hard_Drive_Size = coalesce( nullif( @.Hard_Drive_Size, '' ), h.Hard_Drive_Size )
AND h.Memory = coalesce( nullif( @.Memory, '' ), h.Memory )
AND s.[Name] = coalesce( nullif( @.Name, '' ), s.[Name] )
AND s.Version = coalesce( nullif( @.Version, '' ), s.Version )
AND s.Build = coalesce( nullif( @.Build, '' ), s.Build )
AND s.Install_Status = coalesce( nullif( @.Install_Status, '' ), s.Install_Status )
AND s.Install_Date = coalesce( nullif( @.Install_Date, '' ), s.Install_Date )
AND s.Package_Name = coalesce( nullif( @.Package_Name, '' ), s.Package_Name )
GO
|||Hey Arnie,
Thank you for the tips. I'll be sure to apply them as a newcomer.
The code you supplied me for the @.CREATED and @.MODIFIED parameters didn't create any errors when I Executed the stored procedure. I went into the datagrid on my vb.net form, clicked on the preview button, and again, it threw me the error, "Enter a value for paramter "CREATED". What I did then was added two dates (format is > 04/04/2007) in the datagrid "value" fields to see what it would return. The results it returned are as follows: Type = Int32, Value = 0. It looks as if it reads the data I inputted into the datagrid value field it recognizes this date format as an Integer but somehow didn't return this data in the results window.
Now, when it hit the 4th line, where I started adding the code you updated, "AND n.Workstation_Name = coalesce( nullif( @.Workstation_Name, '' ), n.Workstation_Name )", in the WHERE clause, it threw this error:
Msg 306, Level 16, State 1, Procedure uspPvtSelectCommand, Line 34
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
The bottom line is that the stored procedure will not read the date and time info from the CREATED or the MODIFIED fields in the main.MAC table. This is the format in the database for both fields -> 4/25/2007 5:05:04 AM
I'm still trying to find some material on converting this date and time string value to a datetime datatype value.
Any other suggestions are most welcome.
Wally
Read / Write Into .doc From SQL Stored Procedure
I need to create a flat file as word document, may i know how to write text from stored procedure if a file is already exist then the text will append, how to do it ?
Thank you.
Often, the quality of the responses received is related to our ability to ‘bounce’ ideas off of each other. In the future, to make it easier for us to offer you assistance, and to prevent folks from wasting time on already answered questions, please don't post to multiple newsgroups. Choose the one that best fits your question and post there. Only post to another newsgroup if you get no answer in a day or two (or if you accidentally posted to the wrong newsgroup –and you indicate that you've already posted elsewhere).
Tuesday, March 20, 2012
Reaading and Processing a Recordset from Com object
Hi everybody.
I need help with the next topic.
From a stored procedure in sqlserver, I need to call a com+ dll, this dll connect ot another database diferent to sqlserver y return this dll must return to stored procedure a recordser for ther processing.
I tried with sp_OACreate, sp_OAMethod, sp_OAGetProperty but I did not know how to process a recordset
Thanks
Erik
You can return the recordset data as a multi-dimensional array and this will be streamed to the client. You can use INSERT...EXEC on the server-side to capture the results into a temporary table for example. You can't return the recordset object directly since SQL Server will not know how to process it. See sp_OAMethod topic in BOL for more details.