Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Friday, March 30, 2012

How can I convert datetime to number of minutes

I have a column in a table that stores the number of hours a task took to do. The column TaskDuration is a datetime datatype. I need to convert the hours to something that can be summed. Does anyone how this can be done? I tried CONVERT(nvarchar(5), tblTasks.TaskDuration, 108) but of course the nvarchar(5) cannot be summed. Maybe there is a way to convert the time portion to minutes and divide it by 60, anyway if someone can offer some help I appreciate it.

Try something like this

(datepart(hh, tblTasks.TaskDuration) * 60) + datepart(mm, tblTasks.TaskDuration)

|||

I tried this and it will return the number of minutes for the hours; however, the Parenthesis will not stay around the (datepart(hh, tblTasks.TaskDuration) * 60) in the view. So the (mm) are not being added.

Well it is adding time for the minutes but 30 is calculating to 10, so 03:30 is returning 190 minutes and it should be 210.

Any ideas?

|||I gave you the wrong datepart signifier, try datepart(n, tblTasks.TaskDuration)|||

Ok, so now that I have the number of minutes, can I convert this to hours and minutes. What I mean is the reporting tool needs a numeric column to sum on, so 03:15 needs to be 3.25.

Is this possible?

|||

I tried and it looks to be returning the correct format. If you have any comments, I appreciate them.

CONVERT (FLOAT, DATEPART(hh, dbo.tblVolunteerTasks.VTaskDuration) * 60 + DATEPART(n, dbo.tblVolunteerTasks.VTaskDuration)) / 60

Wednesday, March 28, 2012

How can I combine different rows?

Hi!

I have a table looking like

(username) (account number) (start date) (end date) (product)

wich I can have up to 4 lines for the same client.

I wist to transfert those lines into a new table looking like

(username) (account number) (start date 1) (end date 1) (product 1)
(start date 2) (end date 2) ... (product 4)

How (in SQL) I could do it?>I have a table looking like ..

Please post DDL instead of your personal narrative. If you had done
the talbe properly, i mgiht look like this:

CREATE TABLE AccountHistory
(acct_nbr INTEGER NOT NULL,
product_nbr INTEGER NOT NULL,
product_cnt INTEGER DEFAULT 1 NOT NULL
CHECK(product_cnt BETWEEEN ! AND 4),
PRIMARY KEY (acct_nbr, product_nbr, product_cnt),
user_name VARCHAR(25) NOT NULL,
start_date DATETIME NOT NULL,
end_date DATETIME NOT NULL,
CHECK (start_date < end_date));

I left out the REFERENCES clause you would need and some other
things.

Quote:

Originally Posted by

Quote:

Originally Posted by

>which I can have up to 4 lines [sic] for the same client. <<


Lines appear on a paper form or an input screen; a table has rows.
You need a constraint to enforce this rule.

Quote:

Originally Posted by

Quote:

Originally Posted by

>I wish to transfer those lines into a new table looking like .. <<


You also failed to give any rules for sorting the repeating groups.
But th real question is why are you doing this at all?? That would
violate First Normal Form (1NF). This is not a good way to write
SQL.

Friday, March 23, 2012

How can I automate the column titled as ID NUmber in my database, in VS 2005?

I have a table with a primary key titled as 'ID NUmber' which needs to be created automatically, however every time i add a new record the ID is not added and i have to write it manually i.e. 1, 2, 3.., could you please advice me how i can format this; i know you can do this with microsoft Access but with VS 2005 + VB language this option is not available under data type

*i am using VS 2005 and VB language

Go into design view for the table

toward the bottom, you'll see Identity Specification - open that up and set IS IDentity to True

|||Thank you, i have found the 'IS identity' but mine is set to 'No' and is blocked (i can't click on it). should i be using an specific data type; currenly i am using 'Real' is that right? I had to use 'Real' as with other data types the option for 'primary key' was not available.|||

Generally (though it might be possible some other way that I'm not familiar with), the way to do this is with an INT datatype, so it can automatically increment.

Maybe someone else can chime in here, how to do it some other way

|||

To set a column as an Identity column the datatype has to be one of the INT types - tinyint, smallint, int, bigint etc.

|||

i have used the tinyint to set the IS identity as 'yes', however when i run the database and add a new row to the database the row id is for example 9 instead of 2, even though i have deleted all the previous records and doesn't realise that i have now only 1 row and that the next id should be 2. is there any way to correct this?

|||

You need to read up books online about Identity columns. Once a number is assigned to a row, its gone. Even if the row is deleted the number is gone. Any new rows will get the next number. If you were doing this as a test and want to empty the table and reset the identity you can TRUNCATE the table instead of delete. Again, before doing the truncate, read up books online about the command. You can also use DBCC CHEKCIDENT to reset the seed value.

|||Remember, also - tinyint is defined like this:

tinyint

0 to 255

So - I'd recommend at least using INT

One last thing also - you said that your column is titled "ID Number"

My (and others) recommend that you remove the space (IDNumber) and that you never put spaces in your field or table names. Believe me, this will cause you less grief in the future.

Wednesday, March 21, 2012

How can I achieve this

Hi,
I created a report to display in invoice when passed an invoice number. How
can I display multiple invoices when i pass either a date range? I am not
sure how to get multiple invoices, one after the other on different page.
ThanksOn Jun 2, 12:53 pm, Chris <C...@.discussions.microsoft.com> wrote:
> Hi,
> I created a report to display in invoice when passed an invoice number. How
> can I display multiple invoices when i pass either a date range? I am not
> sure how to get multiple invoices, one after the other on different page.
> Thanks
There are a few different options here. You can use a subreport that
will automatically print out on different pages or you can use a table/
matrix control and group on invoice number and right-click the control
-> select Properties -> select the Groups tab -> select Edit... -> and
select 'Page break at end.' Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant

Monday, March 12, 2012

How can a client application get serial number of SQL server installation

I want to write an application, which will be validated by serial number.
This serial number has to be dependent on serial number, which
is used during SQL Server installation.
In other words - licence key for my client application has to be dependent
on server.
How can my client application get server validation key or another server
specific information (such harddisk serial number of the server, network
adapter card serial number etc)?
Message posted via http://www.sqlmonster.com
You can get the serial number of the SQL Server installation from the
registry key:
HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\80\Registration\CD_KEY.
Jacco Schalkwijk
SQL Server MVP
"Jaroslav Sedlak via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:ead3ca55b3b1403b9d1d532fad4eb192@.SQLMonster.c om...
>I want to write an application, which will be validated by serial number.
> This serial number has to be dependent on serial number, which
> is used during SQL Server installation.
> In other words - licence key for my client application has to be dependent
> on server.
> How can my client application get server validation key or another server
> specific information (such harddisk serial number of the server, network
> adapter card serial number etc)?
> --
> Message posted via http://www.sqlmonster.com
|||Yes, you are right. But this doesn't solve my problem. This registry key
can be read only by an application, which runs on the server.
I want to get licence key of SQL server in application which runs not on
the machine server but on the client machine.
Message posted via http://www.sqlmonster.com
|||You can access the registry from within SQL Server with the undocumented
extended procedure xp_regread. See
http://www.databasejournal.com/featu...le.php/1441251
for more details.
Jacco Schalkwijk
SQL Server MVP
"Jaroslav Sedlak via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:a921286e80de46b891c501f50382388a@.SQLMonster.c om...
> Yes, you are right. But this doesn't solve my problem. This registry key
> can be read only by an application, which runs on the server.
> I want to get licence key of SQL server in application which runs not on
> the machine server but on the client machine.
> --
> Message posted via http://www.sqlmonster.com

How can a client application get serial number of SQL server installation

I want to write an application, which will be validated by serial number.
This serial number has to be dependent on serial number, which
is used during SQL Server installation.
In other words - licence key for my client application has to be dependent
on server.
How can my client application get server validation key or another server
specific information (such harddisk serial number of the server, network
adapter card serial number etc)?
Message posted via http://www.droptable.comYou can get the serial number of the SQL Server installation from the
registry key:
HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\80\Registration\CD_KEY.
Jacco Schalkwijk
SQL Server MVP
"Jaroslav Sedlak via droptable.com" <forum@.droptable.com> wrote in message
news:ead3ca55b3b1403b9d1d532fad4eb192@.SQ
droptable.com...
>I want to write an application, which will be validated by serial number.
> This serial number has to be dependent on serial number, which
> is used during SQL Server installation.
> In other words - licence key for my client application has to be dependent
> on server.
> How can my client application get server validation key or another server
> specific information (such harddisk serial number of the server, network
> adapter card serial number etc)?
> --
> Message posted via http://www.droptable.com|||Yes, you are right. But this doesn't solve my problem. This registry key
can be read only by an application, which runs on the server.
I want to get licence key of SQL server in application which runs not on
the machine server but on the client machine.
Message posted via http://www.droptable.com|||You can access the registry from within SQL Server with the undocumented
extended procedure xp_regread. See
http://www.databasejournal.com/feat...cle.php/1441251
for more details.
Jacco Schalkwijk
SQL Server MVP
"Jaroslav Sedlak via droptable.com" <forum@.droptable.com> wrote in message
news:a921286e80de46b891c501f50382388a@.SQ
droptable.com...
> Yes, you are right. But this doesn't solve my problem. This registry key
> can be read only by an application, which runs on the server.
> I want to get licence key of SQL server in application which runs not on
> the machine server but on the client machine.
> --
> Message posted via http://www.droptable.com

How can a client application get serial number of SQL server installation

I want to write an application, which will be validated by serial number.
This serial number has to be dependent on serial number, which
is used during SQL Server installation.
In other words - licence key for my client application has to be dependent
on server.
How can my client application get server validation key or another server
specific information (such harddisk serial number of the server, network
adapter card serial number etc)?
--
Message posted via http://www.sqlmonster.comYou can get the serial number of the SQL Server installation from the
registry key:
HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\80\Registration\CD_KEY.
--
Jacco Schalkwijk
SQL Server MVP
"Jaroslav Sedlak via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:ead3ca55b3b1403b9d1d532fad4eb192@.SQLMonster.com...
>I want to write an application, which will be validated by serial number.
> This serial number has to be dependent on serial number, which
> is used during SQL Server installation.
> In other words - licence key for my client application has to be dependent
> on server.
> How can my client application get server validation key or another server
> specific information (such harddisk serial number of the server, network
> adapter card serial number etc)?
> --
> Message posted via http://www.sqlmonster.com|||Yes, you are right. But this doesn't solve my problem. This registry key
can be read only by an application, which runs on the server.
I want to get licence key of SQL server in application which runs not on
the machine server but on the client machine.
--
Message posted via http://www.sqlmonster.com|||You can access the registry from within SQL Server with the undocumented
extended procedure xp_regread. See
http://www.databasejournal.com/features/mssql/article.php/1441251
for more details.
--
Jacco Schalkwijk
SQL Server MVP
"Jaroslav Sedlak via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:a921286e80de46b891c501f50382388a@.SQLMonster.com...
> Yes, you are right. But this doesn't solve my problem. This registry key
> can be read only by an application, which runs on the server.
> I want to get licence key of SQL server in application which runs not on
> the machine server but on the client machine.
> --
> Message posted via http://www.sqlmonster.com

Friday, March 9, 2012

How are stored procedures stored in SQL?

A lot of our application logic lives in stored procedures. How can I obtain
the number of lines of code in all of those stored procedures? Can this be
queried?
While we are at it, how about the total number of fields in all of the user
tables?The code is stored in the system table "syscomments".
Example:
use northwind
go
create table #t (colA int identity, colB nvarchar(4000))
insert into #t (colB)
execute sp_helptext 'dbo.sales by year'
select * from #t
order by colA
drop table #t
go
AMB
"JM" wrote:

> A lot of our application logic lives in stored procedures. How can I obta
in
> the number of lines of code in all of those stored procedures? Can this b
e
> queried?
> While we are at it, how about the total number of fields in all of the use
r
> tables?
>
>|||1. I'm guessing you want the total amount of lines for all SPs.
Script out all SPs into Notepad. Don't forget to turn off Word Wrap.
2. Check if this works:
SELECT COUNT(dbo.sysobjects.name) AS totalColumns
FROM dbo.sysobjects INNER JOIN
dbo.syscolumns ON dbo.sysobjects.id =
dbo.syscolumns.id
WHERE (dbo.sysobjects.xtype = 'u')
"JM" <JM@.nospam.com> wrote in message
news:edM6WVeFFHA.3492@.TK2MSFTNGP12.phx.gbl...
> A lot of our application logic lives in stored procedures. How can I
obtain
> the number of lines of code in all of those stored procedures? Can this
be
> queried?
> While we are at it, how about the total number of fields in all of the
user
> tables?
>|||Thanks to both. Very helpful! We have 300,000 lines of code in sp's, I
actually expected the number to be about double that. We have ~24,000
columns in user tables.
This is going in the overall documentation of the app.
"raydan" <rdanjou@.savantsoftNOSPAM.com> wrote in message
news:%23PEPBkeFFHA.560@.TK2MSFTNGP15.phx.gbl...
> 1. I'm guessing you want the total amount of lines for all SPs.
> Script out all SPs into Notepad. Don't forget to turn off Word Wrap.
> 2. Check if this works:
> SELECT COUNT(dbo.sysobjects.name) AS totalColumns
> FROM dbo.sysobjects INNER JOIN
> dbo.syscolumns ON dbo.sysobjects.id =
> dbo.syscolumns.id
> WHERE (dbo.sysobjects.xtype = 'u')
> "JM" <JM@.nospam.com> wrote in message
> news:edM6WVeFFHA.3492@.TK2MSFTNGP12.phx.gbl...
> obtain
> be
> user
>|||This is an adaptation of Alejandro's solution:
Gives you a better count then my first suggestion.
I know. It's a (shudder) cursor solution.
use northwind
go
set nocount on
create table #t (colA int identity, colB nvarchar(4000))
declare @.sp varchar(50)
DECLARE count_Cursor CURSOR FOR
SELECT name
FROM sysobjects
WHERE xtype = 'p'
OPEN count_Cursor
FETCH NEXT FROM count_Cursor INTO @.sp
WHILE @.@.FETCH_STATUS = 0
begin
insert into #t (colB)
execute sp_helptext @.sp
FETCH NEXT FROM count_Cursor INTO @.sp
end
select count(*) from #t
drop table #t
CLOSE count_Cursor
DEALLOCATE count_Cursor
"raydan" <rdanjou@.savantsoftNOSPAM.com> wrote in message
news:%23PEPBkeFFHA.560@.TK2MSFTNGP15.phx.gbl...
> 1. I'm guessing you want the total amount of lines for all SPs.
> Script out all SPs into Notepad. Don't forget to turn off Word Wrap.
> 2. Check if this works:
> SELECT COUNT(dbo.sysobjects.name) AS totalColumns
> FROM dbo.sysobjects INNER JOIN
> dbo.syscolumns ON dbo.sysobjects.id =
> dbo.syscolumns.id
> WHERE (dbo.sysobjects.xtype = 'u')
> "JM" <JM@.nospam.com> wrote in message
> news:edM6WVeFFHA.3492@.TK2MSFTNGP12.phx.gbl...
> obtain
> be
> user
>

Sunday, February 19, 2012

Hot Fix 826161

After applied this hot fix (SQL2000Tools-KB826161-8.00.0819) on the server t
hat has the security patch MS-031 installed, the version number remains at 8
.00.818. Is it supposed to change to 8.00.819?
Do we have the hot fix for SQL 7? Same problem in SQL 7 as it described for
SQL 2000.The build number in the filename of the patch is not necessarily the level
that the file patches sqlservr.exe to... if you re-read the article, it
clearly shows that sqlservr.exe becomes 2000.80.818.0 ... this is what
@.@.VERSION returns.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"RC5640808" <anonymous@.discussions.microsoft.com> wrote in message
news:AF037BF8-210D-40D6-A797-8C783AF17425@.microsoft.com...
> After applied this hot fix (SQL2000Tools-KB826161-8.00.0819) on the server
that has the security patch MS-031 installed, the version number remains at
8.00.818. Is it supposed to change to 8.00.819?
> Do we have the hot fix for SQL 7? Same problem in SQL 7 as it described
for SQL 2000.
>|||Hi
As this fix does not contain a new version of SQLServr.exe the version
number will not change. The hotfix for machines that do not have MS-031 does
have a version of the file which is labelled 818. I am not sure about SQL
Server 7.
John
"RC5640808" <anonymous@.discussions.microsoft.com> wrote in message
news:AF037BF8-210D-40D6-A797-8C783AF17425@.microsoft.com...
> After applied this hot fix (SQL2000Tools-KB826161-8.00.0819) on the server
that has the security patch MS-031 installed, the version number remains at
8.00.818. Is it supposed to change to 8.00.819?
> Do we have the hot fix for SQL 7? Same problem in SQL 7 as it described
for SQL 2000.
>|||I found that once this hot fix is applied, it also fixes the problem for SQL
7.
I think probably is only a bug in the EM and only one copy of EM for the ser
ver that has both SQL 7 and 2000 instances.
Thanks.|||This is correct. The problem is in Enterprise Manager for SQL Server 2000.
It does not affect SQL Server 2000 or SQL Server 7.0 from the server side,
on ly the client side. This is why the problem does not occur for SQL
Server 7.0 after you applied the fix.
Rand
This posting is provided "as is" with no warranties and confers no rights.

Hot Fix 826161

After applied this hot fix (SQL2000Tools-KB826161-8.00.0819) on the server that has the security patch MS-031 installed, the version number remains at 8.00.818. Is it supposed to change to 8.00.819?
Do we have the hot fix for SQL 7? Same problem in SQL 7 as it described for SQL 2000.
The build number in the filename of the patch is not necessarily the level
that the file patches sqlservr.exe to... if you re-read the article, it
clearly shows that sqlservr.exe becomes 2000.80.818.0 ... this is what
@.@.VERSION returns.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"RC5640808" <anonymous@.discussions.microsoft.com> wrote in message
news:AF037BF8-210D-40D6-A797-8C783AF17425@.microsoft.com...
> After applied this hot fix (SQL2000Tools-KB826161-8.00.0819) on the server
that has the security patch MS-031 installed, the version number remains at
8.00.818. Is it supposed to change to 8.00.819?
> Do we have the hot fix for SQL 7? Same problem in SQL 7 as it described
for SQL 2000.
>
|||Hi
As this fix does not contain a new version of SQLServr.exe the version
number will not change. The hotfix for machines that do not have MS-031 does
have a version of the file which is labelled 818. I am not sure about SQL
Server 7.
John
"RC5640808" <anonymous@.discussions.microsoft.com> wrote in message
news:AF037BF8-210D-40D6-A797-8C783AF17425@.microsoft.com...
> After applied this hot fix (SQL2000Tools-KB826161-8.00.0819) on the server
that has the security patch MS-031 installed, the version number remains at
8.00.818. Is it supposed to change to 8.00.819?
> Do we have the hot fix for SQL 7? Same problem in SQL 7 as it described
for SQL 2000.
>
|||I found that once this hot fix is applied, it also fixes the problem for SQL 7.
I think probably is only a bug in the EM and only one copy of EM for the server that has both SQL 7 and 2000 instances.
Thanks.
|||This is correct. The problem is in Enterprise Manager for SQL Server 2000.
It does not affect SQL Server 2000 or SQL Server 7.0 from the server side,
on ly the client side. This is why the problem does not occur for SQL
Server 7.0 after you applied the fix.
Rand
This posting is provided "as is" with no warranties and confers no rights.