Showing posts with label hii. Show all posts
Showing posts with label hii. Show all posts

Sunday, March 25, 2012

Additional 0 to column data

Hi

I have a column in the db with serial number data, on a export that I am doing the data has to be 10 digits long the problem is not all of them are eg

12234

122334343

1234234567

how can i get it to look like this adding an 0 to the front to make the row 10 digits

0000012234

0122334343

1234234567

Thanks

SELECT REPLICATE('0',10 - LEN(CONVERT(VARCHAR(10),Column1))) + CONVERT(VARCHAR(10),Column1)

HTH,

Babu

|||

select right('000000000' + convert(varchar(10),ColumnName),10)

example

declare @.i int
select @.i = 12345

select right('000000000' + convert(varchar(10),@.i),10)

Denis the SQL Menace

http://sqlservercode.blogspot.com/

|||Alternatively perform the formatting in your front end application|||

If the number is to be stored as a number, then this is the best advice. I wouldn't suggest it if this is a value that will be used many different places and never be used in a math equation. For that I would store it in a character string and prepend the zeros.

The real problem comes in all of the different places it is used (reports, data warehouse,etc.) Someone has to format it, and you don't want the user to have to use some UI function to format it. You might do the formatting on the way to the DW and to a reporting data store, but to me it begs the question of the nature of the data. If the nature of the data is a code that happens to be all numbers (but would perform just as well in the application if it was not all numbers, ie 'asd02020' would not change the application as opposed to '000022020', then store it as a character, format it when you save it, and get it over with :)

Thursday, March 22, 2012

Adding users

Hi
I want to programatically attach a DB to an instance of MSDE, and then
create the user, and give permissions to the DB I've just attached.
I can successfully attach the DB, but cannot get the permissions correct
Which sequence of T-SQL commands should I be calling to:
a). create the login in the instance of MSDE
b). associate the login with the newly attached DB
I have played around with:
sp_attach_single_file_db
sp_addlogin
sp_grantdbaccess
sp_grantlogin
but I cannot get a successful logon with the new account, even though the
T-SQL commands run successfully.
Thanks
Hi Paul,
Is there any chance the users already exist in the database you're
attaching? If so, you get into a weird situation because you have users with
the same name but different SID's. If you download a copy of MSDE Manager
from our site (free for personal use), it's got a menu option that lets you
list and fix security ID problems. Might well help.
To avoid these, we normally create the users on the target system by
supplying the sid parameter.
HTH,
Greg Low [MVP]
MSDE Manager SQL Tools
www.whitebearconsulting.com
"Paul Aspinall" <paul@.aspy.co.uk> wrote in message
news:m%IUd.241292$K7.73273@.fe2.news.blueyonder.co. uk...
> Hi
> I want to programatically attach a DB to an instance of MSDE, and then
> create the user, and give permissions to the DB I've just attached.
> I can successfully attach the DB, but cannot get the permissions correct
> Which sequence of T-SQL commands should I be calling to:
> a). create the login in the instance of MSDE
> b). associate the login with the newly attached DB
> I have played around with:
> sp_attach_single_file_db
> sp_addlogin
> sp_grantdbaccess
> sp_grantlogin
> but I cannot get a successful logon with the new account, even though the
> T-SQL commands run successfully.
> Thanks
>
>
|||Hi Greg,
I was reading Paul message and experienced the same problems setting up MSDE.
I installed the MSDE on a machine i was using for the server.
Used (local)netSDK for instance as in the documentation .
Then I accessed the database NorthWind using the SQLClient.
The samples in VB.net now work ok when ran from the server where I installed
MSDE.
However, I then got very bold, and tried to access the NorthWind database
from another computer that was setup on our network.
I added a login name, added a role and a member, granted premission.
Then in the vb.net program I tried to open the database with the same code
from the program on the server. I did change the server name to the Name of
the computer that MSDE was installed on. I also tried the IP address as the
server.
I kept getting the error "Server not found or do not have premission.
WHAT AM I DOING WRONG?
Best regards,
Dave
"Greg Low [MVP]" wrote:

> Hi Paul,
> Is there any chance the users already exist in the database you're
> attaching? If so, you get into a weird situation because you have users with
> the same name but different SID's. If you download a copy of MSDE Manager
> from our site (free for personal use), it's got a menu option that lets you
> list and fix security ID problems. Might well help.
> To avoid these, we normally create the users on the target system by
> supplying the sid parameter.
> HTH,
> --
> Greg Low [MVP]
> MSDE Manager SQL Tools
> www.whitebearconsulting.com
> "Paul Aspinall" <paul@.aspy.co.uk> wrote in message
> news:m%IUd.241292$K7.73273@.fe2.news.blueyonder.co. uk...
>
>

adding up column values (asp & access 2000)

Hi

I've got a quandry - I have a detailed database that handles advert
orders between a design agency and printers / magazines etc.

I want to add up the total spent by the client and put the results to a

field.

I've actually done that using a query table in access - it should be
quite simple as i can bind the 'total amount' to my table - the only
thing it does not currently do is filter the total based on the month
selected.

For example if you look at
http://www.daneverton.com/dg2data/months/2006-12.asp
The data here is filtered by the issue equaling Dec-2006

The actual order total is 13,622 but the column is showing the total
for all entries to date (a years worth = 422,048)

I'm sure that there is only a basic tweak required but i'm banging my
head over what to do

The sql is "SELECT * FROM monnodraught, q_monodraught_total WHERE
[Issue / Edition] LIKE ? ORDER BY Publication ASC"

Any help gladly received.Hi Dan,

What is the SQL behind: q_monodraught_total ?
Quote:
The sql is "SELECT * FROM monnodraught, q_monodraught_total WHERE
[Issue / Edition] LIKE ? ORDER BY Publication ASC"
I'm thinking you might benefit from a SELECT SUM... query
SELECT SUM(fieldname) FROM table WHERE condition ORDER BY fieldname; SELECT SUM(Age) FROM Persons WHERE Age>20good luck ;o)

Cheers,
Douglas

------------------------

"Dan" <mail@.daneverton.comwrote in message news:1164792444.626863.242620@.h54g2000cwb.googlegr oups.com...
Hi

I've got a quandry - I have a detailed database that handles advert
orders between a design agency and printers / magazines etc.

I want to add up the total spent by the client and put the results to a

field.

I've actually done that using a query table in access - it should be
quite simple as i can bind the 'total amount' to my table - the only
thing it does not currently do is filter the total based on the month
selected.

For example if you look at
http://www.daneverton.com/dg2data/months/2006-12.asp
The data here is filtered by the issue equaling Dec-2006

The actual order total is 13,622 but the column is showing the total
for all entries to date (a years worth = 422,048)

I'm sure that there is only a basic tweak required but i'm banging my
head over what to do

The sql is "SELECT * FROM monnodraught, q_monodraught_total WHERE
[Issue / Edition] LIKE ? ORDER BY Publication ASC"

Any help gladly received.

Tuesday, March 20, 2012

Adding tables to SQL server database in visual studio?

Hi

I keep reading it's possible to add, amend ,etc. tables in visual studio but to do so I need access to the features that allow this.
I can connect to the database but I haven't been able to use any of these database features since they are "blanked" out.
Obviously, I can do all this at the server but ideally I would like to do it remotely.

Any suggestions?
Thanks in advance.In your server explorer, can you navigate to the tables?
-Servers
- <your server>
- SQL Servers
- <your SQL server>
- <your database>
- tables

From there you should be able to add, change, or delete tables.

-Ian|||Hi Ian

Thanks for the reply.

I can navigate to the tables but the menu features are not available for adding,etc. tables.
Could it be something at the server end that I need to change?

Thanks in advance.sql

Monday, March 19, 2012

Adding SQL Server Database file to the website

Hi!!!

I have a database called "test_DB" i have one table and some data on it. I uploaded the website and created an SQL Server account to upload the database. Can you please help me to do that task. Is there any step by step directions to do it and what files i need to add ( like ".mdf" or others...) I appreciate your help!!!

Thanks...

You are using an ISP for the hosting? They should have some way of setting that up. You probably should send them an email for uploading a sql server database. If you own the server, do a database detach/attach, which is simple.

Adding RunningTotal field from runtime

Hi!

I have a problem adding RunningTotal field from runtime...

Here is what i allready done:

Adding gruop:
.AddGroup 0, .unFKonto.Field, crGCAnyValue, crAscendingOrder

Adding unBoundField in GroupHeader section(lSectH)

Dim crKonto As FieldObject
Set crKonto = crReport.Sections(lSectH).AddUnboundFieldObject(crStringField, 200, 20)
With crKonto
.Font.Name = "Arial Narrow"
.SetUnboundFieldSource "{ado.Konto}"
.width = 1000
End With

All that works great but now i need to add RunningTotal in GruopFooter section
How to do that?

Here is what i allready done:
Dim crRTtest As RunningTotalFieldDefinition

Set crRTtest = .RunningTotalFields.Add("Sum of Konto")
crRTtest.SummaryType = iSum

Well, how to add crRTtest to section 5 after setting all needed properties?

regardsDone!

Dim crRTtest As RunningTotalFieldDefinition
Dim crBla As FieldObject
With crReport
Set crRTtest = .RunningTotalFields.Add("Sum of sss")

crRTtest.SummaryType = crSTSum
crRTtest.SetNoEvaluateCondition

crRTtest.SetResetConditionField .unFKonto.Field
crRTtest.SetSummarizedField .DokPrice.Field
Set crBla = .Sections(lSecF).AddFieldObject(crRTtest, 200, 20)
End With

Spent 3 days on that...
It was confusing to me that CR have AddBlobObject, AddSummaryFieldObject and so on but no AddRunningTotalFieldbject.

p.s.
Do you know where to find good help for developer on CR v8?
Developr.hlp is cunfusing and not very helpfull

Tuesday, March 6, 2012

Adding more RAM for MS SQL Server 2000

Hi
I have a MS SQL Server 2000 SP3 on MS Windows Server 2003 SP1 machine at my
hand. The SQL Server is configured for dynamic memory allocation. The machine
had 2GB of RAM in it when I installed the SQL Server. Now I've installed two
more gigabytes of RAM into the machine and I want to allow the SQL Server to
use a total of 3GB of RAM (by means of turning on the /3GB switch in Windows
boot.ini).
Do I also have to reconfigure any SQL Server parameters after enabling it to
use the additional gigabyte of RAM?
Many thanks,
Oskar
No. All you have to do is add the /3GB switch to boot.ini and reboot.
If you wanted to address > 4GB of RAM then you would have to start
playing with AWE but <= 4GB is addressable with normal windows memory
addressing & therefore normal MSSQL dynamic memory management.
*mike hodgson* |/ database administrator/ | mallesons stephen jaques
*T* +61 (2) 9296 3668 |* F* +61 (2) 9296 3885 |* M* +61 (408) 675 907
*E* mailto:mike.hodgson@.mallesons.nospam.com |* W* http://www.mallesons.com
Oskar wrote:

>Hi
>I have a MS SQL Server 2000 SP3 on MS Windows Server 2003 SP1 machine at my
>hand. The SQL Server is configured for dynamic memory allocation. The machine
>had 2GB of RAM in it when I installed the SQL Server. Now I've installed two
>more gigabytes of RAM into the machine and I want to allow the SQL Server to
>use a total of 3GB of RAM (by means of turning on the /3GB switch in Windows
>boot.ini).
>Do I also have to reconfigure any SQL Server parameters after enabling it to
>use the additional gigabyte of RAM?
>--
>Many thanks,
>Oskar
>
>
|||Hi,
This will work out if your SQL server 2000 edition is Enterprise or Developer. Standard edition can support a maximum of 2 GB only.
Thanks
Hari
SQL Server MVP
"Mike Hodgson" <mike.hodgson@.mallesons.nospam.com> wrote in message news:OvpsIwbZFHA.4088@.TK2MSFTNGP15.phx.gbl...
No. All you have to do is add the /3GB switch to boot.ini and reboot. If you wanted to address > 4GB of RAM then you would have to start playing with AWE but <= 4GB is addressable with normal windows memory addressing & therefore normal MSSQL dynamic memory management.
mike hodgson | database administrator | mallesons stephen jaques
T +61 (2) 9296 3668 | F +61 (2) 9296 3885 | M +61 (408) 675 907
E mailto:mike.hodgson@.mallesons.nospam.com | W http://www.mallesons.com
Oskar wrote:
Hi
I have a MS SQL Server 2000 SP3 on MS Windows Server 2003 SP1 machine at my
hand. The SQL Server is configured for dynamic memory allocation. The machine
had 2GB of RAM in it when I installed the SQL Server. Now I've installed two
more gigabytes of RAM into the machine and I want to allow the SQL Server to
use a total of 3GB of RAM (by means of turning on the /3GB switch in Windows
boot.ini).
Do I also have to reconfigure any SQL Server parameters after enabling it to
use the additional gigabyte of RAM?
Many thanks,
Oskar

Adding more RAM for MS SQL Server 2000

Hi
I have a MS SQL Server 2000 SP3 on MS Windows Server 2003 SP1 machine at my
hand. The SQL Server is configured for dynamic memory allocation. The machin
e
had 2GB of RAM in it when I installed the SQL Server. Now I've installed two
more gigabytes of RAM into the machine and I want to allow the SQL Server to
use a total of 3GB of RAM (by means of turning on the /3GB switch in Windows
boot.ini).
Do I also have to reconfigure any SQL Server parameters after enabling it to
use the additional gigabyte of RAM?
Many thanks,
OskarNo. All you have to do is add the /3GB switch to boot.ini and reboot.
If you wanted to address > 4GB of RAM then you would have to start
playing with AWE but <= 4GB is addressable with normal windows memory
addressing & therefore normal MSSQL dynamic memory management.
*mike hodgson* |/ database administrator/ | mallesons stephen jaques
*T* +61 (2) 9296 3668 |* F* +61 (2) 9296 3885 |* M* +61 (408) 675 907
*E* mailto:mike.hodgson@.mallesons.nospam.com |* W* http://www.mallesons.com
Oskar wrote:

>Hi
>I have a MS SQL Server 2000 SP3 on MS Windows Server 2003 SP1 machine at my
>hand. The SQL Server is configured for dynamic memory allocation. The machi
ne
>had 2GB of RAM in it when I installed the SQL Server. Now I've installed tw
o
>more gigabytes of RAM into the machine and I want to allow the SQL Server t
o
>use a total of 3GB of RAM (by means of turning on the /3GB switch in Window
s
>boot.ini).
>Do I also have to reconfigure any SQL Server parameters after enabling it t
o
>use the additional gigabyte of RAM?
>--
>Many thanks,
>Oskar
>
>|||Hi,
This will work out if your SQL server 2000 edition is Enterprise or Develope
r. Standard edition can support a maximum of 2 GB only.
Thanks
Hari
SQL Server MVP
"Mike Hodgson" <mike.hodgson@.mallesons.nospam.com> wrote in message news:Ovp
sIwbZFHA.4088@.TK2MSFTNGP15.phx.gbl...
No. All you have to do is add the /3GB switch to boot.ini and reboot. If yo
u wanted to address > 4GB of RAM then you would have to start playing with A
WE but <= 4GB is addressable with normal windows memory addressing & therefo
re normal MSSQL dynamic memory management.
mike hodgson | database administrator | mallesons stephen jaques
T +61 (2) 9296 3668 | F +61 (2) 9296 3885 | M +61 (408) 675 907
E mailto:mike.hodgson@.mallesons.nospam.com | W http://www.mallesons.com
Oskar wrote:
Hi
I have a MS SQL Server 2000 SP3 on MS Windows Server 2003 SP1 machine at my
hand. The SQL Server is configured for dynamic memory allocation. The machin
e
had 2GB of RAM in it when I installed the SQL Server. Now I've installed two
more gigabytes of RAM into the machine and I want to allow the SQL Server to
use a total of 3GB of RAM (by means of turning on the /3GB switch in Windows
boot.ini).
Do I also have to reconfigure any SQL Server parameters after enabling it to
use the additional gigabyte of RAM?
Many thanks,
Oskar

Adding More processors not helping improve performances

Hi
I had Enterprise SQL Server installed on my server with 4 processors. Its was great performances in the beginning. Later we got more processes to run.
So, I upgrade hardware to 8 Processors, but surprisingly no improvement in processing time wise. My processes is taking same time as they used to take when I have 4 processors.
E.g. Job-1 was taking 2:15 minutes with 4 processors, it is still taking same time with 8 processors.
Is there anything I am missing while upgrading to processors? I have windows Advanced Server 2000.
appreciate your help.
Thankx
JP
Processor power is only one possible constraint on your system. It is probably that memory, disk, network or design is your current contraint. I would recommend monitoring your database to determine what resource the SQL Server is waiting for.
|||SQL really prefers for each processor to work on a different connection,
instead of having multiple processors work on a single piece of work... You
might check in SQL Enterprise Manager,Right click your
server->Properties->Processors and make sure Use all processors is selected
and Max processors per query is whatever you wish...
However you are likely to get better throughput ( not faster for a single
query tho) by setting max processors per query to 2 or 1. ...
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"JP" <anonymous@.discussions.microsoft.com> wrote in message
news:7DBC43F5-09E2-4B37-A91F-BDADC78EBCF9@.microsoft.com...
> Hi
> I had Enterprise SQL Server installed on my server with 4 processors. Its
was great performances in the beginning. Later we got more processes to run.
> So, I upgrade hardware to 8 Processors, but surprisingly no improvement in
processing time wise. My processes is taking same time as they used to take
when I have 4 processors.
> E.g. Job-1 was taking 2:15 minutes with 4 processors, it is still taking
same time with 8 processors.
> Is there anything I am missing while upgrading to processors? I have
windows Advanced Server 2000.
> appreciate your help.
> Thankx
> JP
>
|||I already have Use all processors checked out.. There is no issues of performance.
Just wondering, how come it is taking same time as 4 processors while I have 8 processors.
Or I believe, 4 processors of 2 GHz is maxed out and when I add another 4 processors it is doing better load sharing instead of gaining timewise performances.
-- Wayne Snyder wrote: --
SQL really prefers for each processor to work on a different connection,
instead of having multiple processors work on a single piece of work... You
might check in SQL Enterprise Manager,Right click your
server->Properties->Processors and make sure Use all processors is selected
and Max processors per query is whatever you wish...
However you are likely to get better throughput ( not faster for a single
query tho) by setting max processors per query to 2 or 1. ...
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"JP" <anonymous@.discussions.microsoft.com> wrote in message
news:7DBC43F5-09E2-4B37-A91F-BDADC78EBCF9@.microsoft.com...[vbcol=seagreen]
> Hi
was great performances in the beginning. Later we got more processes to run.[vbcol=seagreen]
processing time wise. My processes is taking same time as they used to take
when I have 4 processors.[vbcol=seagreen]
same time with 8 processors.[vbcol=seagreen]
windows Advanced Server 2000.
> Thankx
> JP
>

Adding More processors not helping improve performances

Hi
I had Enterprise SQL Server installed on my server with 4 processors. Its wa
s great performances in the beginning. Later we got more processes to run.
So, I upgrade hardware to 8 Processors, but surprisingly no improvement in p
rocessing time wise. My processes is taking same time as they used to take w
hen I have 4 processors.
E.g. Job-1 was taking 2:15 minutes with 4 processors, it is still taking sam
e time with 8 processors.
Is there anything I am missing while upgrading to processors? I have windows
Advanced Server 2000.
appreciate your help.
Thankx
JPProcessor power is only one possible constraint on your system. It is proba
bly that memory, disk, network or design is your current contraint. I would
recommend monitoring your database to determine what resource the SQL Serve
r is waiting for.|||SQL really prefers for each processor to work on a different connection,
instead of having multiple processors work on a single piece of work... You
might check in SQL Enterprise Manager,Right click your
server->Properties->Processors and make sure Use all processors is selected
and Max processors per query is whatever you wish...
However you are likely to get better throughput ( not faster for a single
query tho) by setting max processors per query to 2 or 1. ...
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"JP" <anonymous@.discussions.microsoft.com> wrote in message
news:7DBC43F5-09E2-4B37-A91F-BDADC78EBCF9@.microsoft.com...
> Hi
> I had Enterprise SQL Server installed on my server with 4 processors. Its
was great performances in the beginning. Later we got more processes to run.
> So, I upgrade hardware to 8 Processors, but surprisingly no improvement in
processing time wise. My processes is taking same time as they used to take
when I have 4 processors.
> E.g. Job-1 was taking 2:15 minutes with 4 processors, it is still taking
same time with 8 processors.
> Is there anything I am missing while upgrading to processors? I have
windows Advanced Server 2000.
> appreciate your help.
> Thankx
> JP
>|||I already have Use all processors checked out.. There is no issues of perfor
mance.
Just wondering, how come it is taking same time as 4 processors while I have
8 processors.
Or I believe, 4 processors of 2 GHz is maxed out and when I add another 4 pr
ocessors it is doing better load sharing instead of gaining timewise perform
ances.
-- Wayne Snyder wrote: --
SQL really prefers for each processor to work on a different connection,
instead of having multiple processors work on a single piece of work... You
might check in SQL Enterprise Manager,Right click your
server->Properties->Processors and make sure Use all processors is selected
and Max processors per query is whatever you wish...
However you are likely to get better throughput ( not faster for a single
query tho) by setting max processors per query to 2 or 1. ...
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"JP" <anonymous@.discussions.microsoft.com> wrote in message
news:7DBC43F5-09E2-4B37-A91F-BDADC78EBCF9@.microsoft.com...
> Hi
was great performances in the beginning. Later we got more processes to run.[vbcol=seagreen]
processing time wise. My processes is taking same time as they used to take
when I have 4 processors.[vbcol=seagreen]
same time with 8 processors.[vbcol=seagreen]
windows Advanced Server 2000.[vbcol=seagreen]
> Thankx
> JP
>

Friday, February 24, 2012

Adding Hyperlink Using Report builder

Hi

I want to add Hyperlink to report, using report builder.

or to add it to report model

does any body has a clue

ruvy

Sorry, there's no way to do this in RS 2005 Report Builder or Model Designer.

You might be able to knock up the RDL that comes out of Report Builder, in Report Designer (or any text editor), to add your Hyperlink action, but then you won't be able to reload the RDL in Report Builder.

|||Thanks , at least i wont search for this feature

Adding execute permission to stored procedures

Hi

I am currently using SQL server 2005 express edition for a website I have created using Asp.Net 2.

For this website I call stored procedures that I have created in the databse to return any page data. However, I keep getting error messages say that the login does not have execute permission for the stored procedure.

In Sql Server 2005 there does not seem to be an easy way to grant permissions to a stored procedure as you add them. I say this because when I used Sql Server 2000 I would just add the stored procedure, rigth click on it and grant permission to the user.

Now this does not seem to be the case with the new version of sql server and I was just wondering whether there is now a new, easy way of doing this.

If anyone can point me in the right direction on this...

I have managed to get this working by going into the properties of the users atached to the database, adding a list of stored procedures to the "scalables" area and individually ticking the execute checkboxs. However, when I return to add a new stored procedure, the list has disapeared. Is this a bug with Sql server 2005?

Thanking you in advance

A db owner can execute, alternatively you could add server roles to the login such as sysadmin may be overkill though

Function SetLoginsDbOwner()Dim strcmdAsString

strcmd = "exec sp_addrolemember N'db_owner', N'MyLoginName_IWantSPExecutePerm'"

Dim dcAsNew OleDbConnection(connstringL)Dim cmdAsNew OleDbCommand(strcmd, dc)Try

dc.Open()

cmd.ExecuteNonQuery()

Catch exAs OleDbException

Label3.Text = ex.ToString()

Finally

dc.Close()

EndTryEndFunction

Sunday, February 19, 2012

Adding DEFAULT columns

Hi

I have a table that currently has 466 columns and about 700,000
records. Adding a new DEFAULT column to this table takes a long time.

It it a lot faster to recreate the table with the new columns and then
copy all of the data across.

As far as I am aware when you add a DEFAULT column the following
happens:

a) The column is added with a NULL property
b) Each row is updated to be set to the DEFAULT value
c) The column is changed to NOT NULL.

However, adding the column as NOT NULL with the DEFAULT seems to take a
lot longer than if I do steps a) - c) separately.

When I say a long time, adding just a single DEFAULT column takes
around 6 hours. Surely it should not take this long?

There is a trigger on this table but disabling this does not seem to
make much difference.

Can anybody give me any advice on the use of DEFAULT columns please?
When should they be used, benefits, disadvantages, alternatives etc.
Also should it really take as long as it is taking or is there a
problem with my setup?

If I am honest I can't see why DEFAULT columns should be used as the
values could always be inserted explicitly via the application
Thanks in Advance.

PaulI think you may be able to speed it up by using the NoCheck option, so it
doesn't look at the existing data.

I didn't know that specifying a default updates the null values in the
table - so you are either incorrect, or I have an incomplete understanding.

But I am pretty sure that having so many columns isn't helping you in the
least bit, and may be the real reason.

Splitting the tables apart and using a view to be backwards compatible (with
an 'instead of ' trigger for updates) - aught to make things go faster.
Especially if all or the most frequent searchable columns stay in one of the
new tables (a hub table as it were).

If the data values are ALWAYS explicitly added ALL the time, there is no
reason for a default.
You may need to beat up on some wayward programmer to guarantee that they
get populated each and every time with the correct values - But since I
don't like violence (nor the testing to find the problem), I add defaults
to guarantee that happens regardless. Also it is possible to do an insert
without a column list and specify defaults (so that all the columns get the
default values), which could be useful in some instances.

"Paul" <paulwragg2323@.hotmail.com> wrote in message
news:1103024817.227784.219090@.z14g2000cwz.googlegr oups.com...
> Hi
> I have a table that currently has 466 columns and about 700,000
> records. Adding a new DEFAULT column to this table takes a long time.
> It it a lot faster to recreate the table with the new columns and then
> copy all of the data across.
> As far as I am aware when you add a DEFAULT column the following
> happens:
> a) The column is added with a NULL property
> b) Each row is updated to be set to the DEFAULT value
> c) The column is changed to NOT NULL.
> However, adding the column as NOT NULL with the DEFAULT seems to take a
> lot longer than if I do steps a) - c) separately.
> When I say a long time, adding just a single DEFAULT column takes
> around 6 hours. Surely it should not take this long?
> There is a trigger on this table but disabling this does not seem to
> make much difference.
> Can anybody give me any advice on the use of DEFAULT columns please?
> When should they be used, benefits, disadvantages, alternatives etc.
> Also should it really take as long as it is taking or is there a
> problem with my setup?
> If I am honest I can't see why DEFAULT columns should be used as the
> values could always be inserted explicitly via the application
> Thanks in Advance.
> Paul|||Thanks for the response David.

I have suggested that we split this table up and I think this will be
eventually done (it's a case of having the time up front to do this).

I wasn't saying that adding a DEFAULT value to the column updates
existing data - rather that when a new DEFAULT column is added it
follows the steps a) - c) in order to add the new column.

As the table is so large I think I need to investigate the way the data
for this table is actually stored. At present we have no clustered
index on this table which is probably also contributing to the problem.
I don't know too much about the way the data is stored to be honest!|||OK, I get it now, you are adding a column and not just binding a new default
to an existing column.

Copy into the new table, drop the original, and do a sp_rename.
While you are at it break the table apart - If you can't find the time to do
it right, when will you find the time to do over and over incorrectly.

Get one of those MCSD prep books for the SQL Server Design Exam to find out
how stuff gets stored in a database. Their 1st or 2nd chapter normally goes
over devices, extents, pages and all that stuff.

I am sure there are a boat load of free sources on the Web on that as well.

"Paul" <paulwragg2323@.hotmail.com> wrote in message
news:1103033046.110249.69780@.f14g2000cwb.googlegro ups.com...
> Thanks for the response David.
> I have suggested that we split this table up and I think this will be
> eventually done (it's a case of having the time up front to do this).
> I wasn't saying that adding a DEFAULT value to the column updates
> existing data - rather that when a new DEFAULT column is added it
> follows the steps a) - c) in order to add the new column.
> As the table is so large I think I need to investigate the way the data
> for this table is actually stored. At present we have no clustered
> index on this table which is probably also contributing to the problem.
> I don't know too much about the way the data is stored to be honest!|||Paul (paulwragg2323@.hotmail.com) writes:
> It it a lot faster to recreate the table with the new columns and then
> copy all of the data across.

Is that a question or a statement? Which "It" is a typo for "is"?

> When I say a long time, adding just a single DEFAULT column takes
> around 6 hours. Surely it should not take this long?

Just because "ALTER TABLE tbl ADD col DEFAULT 0" is easy to type, that
does not mean that it executes equally fast. There is a lot of work to
be done - since all rows expand, basically all pages have to be written.

In our shop we do all table changes the long way - rename, create new,
insert over, move foreign keys, drop old. We have a build that generates
a skeleton for this manoeuvre. One reason we do this is that ALTER TABLE
only can handle some changes, and you can not insert columns in the
middle with. (And our scheme was established in 6.5 when you could do
even less with ALTER TABLE.)

Generally, I would not expect reload of a 700000 rows table, not even
that wide to take six hours. Also, when moving over, you can do that
in chunks.

> There is a trigger on this table but disabling this does not seem to
> make much difference.

The trigger is not fired when you to ALTER TABLE. Note that if you do
the long way, you will need to recreate the trigger. Whether you do
that before or after you reload the data depends on whether you want
the checks in the trigger to be performed (I usually want to). But for
performance, it's best to recreate the trigger after the data move.

> Can anybody give me any advice on the use of DEFAULT columns please?
> When should they be used, benefits, disadvantages, alternatives etc.
> Also should it really take as long as it is taking or is there a
> problem with my setup?

If you need to add to existing column to a database, and you don't want
NULL values in the column, the a default value is a good way to go, to
avoid problems with existing software that writes to this table. And,
even if existing software is rewritten - it may after all be a single
GUI form - existing data needs to be handled.

Sometimes NULL values can be feasible, but for instance a bit column
is typically NOT NULL. I think the choice should be made from the
anticpated use in the future, and not what is the most convenient
right now.

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

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||A technique that I sometimes use with large tables is SELECT ... INTO
followed by a drop and a rename. This is minimally logged in the SIMPLE or
BULK_LOGGED recovery model.

Whether or not this is faster depends on the particulars of the changes made
and the indexes that need to be rebuilt.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"Paul" <paulwragg2323@.hotmail.com> wrote in message
news:1103024817.227784.219090@.z14g2000cwz.googlegr oups.com...
> Hi
> I have a table that currently has 466 columns and about 700,000
> records. Adding a new DEFAULT column to this table takes a long time.
> It it a lot faster to recreate the table with the new columns and then
> copy all of the data across.
> As far as I am aware when you add a DEFAULT column the following
> happens:
> a) The column is added with a NULL property
> b) Each row is updated to be set to the DEFAULT value
> c) The column is changed to NOT NULL.
> However, adding the column as NOT NULL with the DEFAULT seems to take a
> lot longer than if I do steps a) - c) separately.
> When I say a long time, adding just a single DEFAULT column takes
> around 6 hours. Surely it should not take this long?
> There is a trigger on this table but disabling this does not seem to
> make much difference.
> Can anybody give me any advice on the use of DEFAULT columns please?
> When should they be used, benefits, disadvantages, alternatives etc.
> Also should it really take as long as it is taking or is there a
> problem with my setup?
> If I am honest I can't see why DEFAULT columns should be used as the
> values could always be inserted explicitly via the application
> Thanks in Advance.
> Paul

adding DB from another computer

Hi!
I have copied from other computer, from location "C:\Program Files\Microsoft
SQL Server\MSSQL.2\MSSQL\Data" files my_db.mdf and md_db_log.ldf to other
computer to the same location, and I can't see this DB. How can I import DB
using files above?
Regards,
AreqYOu will either have to attach the database using the GUI commands for that
(Right Click on the server, either in EM or SSMS) and select attach
database, then select the appropiate database files, or use the TSQL command
sp_attachdb to attach the files. See more details about the TSQL command in
the BOL (SQL Server Help files).
Jens K. Suessmeyer.
http://www.sqlserver2005.de
--
"Areq" <areq@.op.com> wrote in message
news:eu1h3n$kqe$1@.nemesis.news.tpi.pl...
> Hi!
> I have copied from other computer, from location "C:\Program
> Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data" files my_db.mdf and
> md_db_log.ldf to other computer to the same location, and I can't see this
> DB. How can I import DB using files above?
> Regards,
> Areq
>|||Areq,
Check BOL for sp_attach_db. That is probably what you need.
-- Bill
"Areq" <areq@.op.com> wrote in message
news:eu1h3n$kqe$1@.nemesis.news.tpi.pl...
> Hi!
> I have copied from other computer, from location "C:\Program
> Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data" files my_db.mdf and
> md_db_log.ldf to other computer to the same location, and I can't see this
> DB. How can I import DB using files above?
> Regards,
> Areq
>|||Use sp_attach_db
Here is an example from BOL
EXEC sp_attach_db @.dbname = N'pubs',
@.filename1 = N'c:\Program Files\Microsoft SQL
Server\MSSQL\Data\pubs.mdf',
@.filename2 = N'c:\Program Files\Microsoft SQL
Server\MSSQL\Data\pubs_log.ldf'
Jack Vamvas
___________________________________
Advertise your IT vacancies for free at - http://www.ITjobfeed.com
"Areq" <areq@.op.com> wrote in message
news:eu1h3n$kqe$1@.nemesis.news.tpi.pl...
> Hi!
> I have copied from other computer, from location "C:\Program
> Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data" files my_db.mdf and
> md_db_log.ldf to other computer to the same location, and I can't see this
> DB. How can I import DB using files above?
> Regards,
> Areq
>

Adding datetime fields

Hi

I'm learning SQL, stuck on a problem, and would be very grateful if someone could point me in the right direction please.

I have a table that contains employee overtime data. The table contains the employee ID number, the work week ID, basic hours, and overtime hours worked.
What i want to do is SUM(OThrs) for a particular employee to get the total OT hours worked in a given workweek.

However, as I understand it the datetime datatype stores its value as a value measured from a base date of Dec-30-1899. As it wouldn't make sense to add the datetime fields due to this, is there any way around it?

The OThrs is brought in from a csv file through a DTS package and is in the format of.... eg 07:45, 13:20, 02:12, 08:10

So if those times above were all for the same employee in the same work week, it would total 31:27

I'd be grateful for some poiters on this problem.
Thanks & Regards
MartyT

If you did not specify any date part in the datetime value, then the date portion will default to 1900-01-01. Confirm that this is the case for those values. Assuming this condition, you can do the following:

select t.EmployeeId, t.WorkWeekId,
convert(varchar(5), dateadd(minute, sum(datediff(minute, '', t.Othrs)), ''), 114) as total_ot_hours
from tbl as t
group by t.EmployeeId, t.WorkWeekId

Note that the above query only has resolution less than 24 hrs. If you need more than that, then take the minute value directly and generate the hour/minutes part yourself.|||That's a big help. Thanks for your time - much appreciated

Thursday, February 9, 2012

Adding an Article to a Publication

Hi:
I have a publication with larger sql table articles. I want to add another
article (small table). To start replicating, I will need to reinitialize and
rerun the snaphot. I don't want to run the snapshot during the day time
because it may block other users because publication has some large tables in
it.
Is there anyway that I can replicate just that table to subsriber during the
day time?
Thanks a lot
Hi Mike,
You shouldn't need to reinitialize your existing subscription in order to
get snapshot data for the new article propagated to the subscriber. And if
you have a transactional publication with the immediate_sync property set to
false, the snapshot agent will only generate bcp data for the new article.
-Raymond
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:43347180-986E-474C-8C45-EB83BEB62DE5@.microsoft.com...
> Hi:
> I have a publication with larger sql table articles. I want to add
> another
> article (small table). To start replicating, I will need to reinitialize
> and
> rerun the snaphot. I don't want to run the snapshot during the day time
> because it may block other users because publication has some large tables
> in
> it.
> Is there anyway that I can replicate just that table to subsriber during
> the
> day time?
> Thanks a lot
>
|||Thanks Raymond. Where will I see immediate_sync property.
"Raymond Mak [MSFT]" wrote:

> Hi Mike,
> You shouldn't need to reinitialize your existing subscription in order to
> get snapshot data for the new article propagated to the subscriber. And if
> you have a transactional publication with the immediate_sync property set to
> false, the snapshot agent will only generate bcp data for the new article.
> -Raymond
> "Mike" <Mike@.discussions.microsoft.com> wrote in message
> news:43347180-986E-474C-8C45-EB83BEB62DE5@.microsoft.com...
>
>
|||Hi Mike,
You can select the value of the immediate_sync property directly from
syspublications at the publisher database.
-Raymond
"Mike" <Mike@.discussions.microsoft.com> wrote in message
news:E58CEE1E-B55D-4DB3-8E4F-1AB5387C36F2@.microsoft.com...[vbcol=seagreen]
> Thanks Raymond. Where will I see immediate_sync property.
> "Raymond Mak [MSFT]" wrote:

Adding an article in merge replication

Hi
I want to add an article to an existing publication using merge replication,
the database is around 5 Gb. Using sp_addmergearticle defaults to invalidate
the snapshot and a new one has to be created. When the new snapshot is
applied to the subscriber is there anyway of just applying just the new
article and its data and nothing else. Setting the pre_creation_command to
'none' only seems to ignore the creation of tables and not the bcp of data
into them.
many thanks
Hi Rob,
When you add an incremental article by specifying @.force_invalidate_snapshot
and generate the snapshot, the snapshot is generated for all the articles.
However when you apply the snapshot at the subscriber, it will apply *only*
the incremental article schema files and data. It will *not* be applying the
snapshot for all the other articles, unless you are reinitializing the
subscriber.
Hope that helps
--Mahesh
[ This posting is provided "as is" with no warranties and confers no
rights. ]
"robham" <nospam@.co.uk> wrote in message
news:%235fLYMIrEHA.4008@.TK2MSFTNGP14.phx.gbl...
> Hi
> I want to add an article to an existing publication using merge
replication,
> the database is around 5 Gb. Using sp_addmergearticle defaults to
invalidate
> the snapshot and a new one has to be created. When the new snapshot is
> applied to the subscriber is there anyway of just applying just the new
> article and its data and nothing else. Setting the pre_creation_command to
> 'none' only seems to ignore the creation of tables and not the bcp of data
> into them.
> many thanks
>