Showing posts with label size. Show all posts
Showing posts with label size. Show all posts

Sunday, March 25, 2012

Check multiple records before inserting records

i have a table which is having size and pieces information

Size, pieces, sizeID, sizecombID

S, 1, 1, 1

M, 3, 2, 1

L, 3, 3, 1

XL, 1, 4, 1

I have two questions :-

1. If user enters the same information i.e. same sizes and same pieces then my stored procedure should not add these four records, instead it should return existing value of SizecombID(which stands for size combination ID)

2. If a totally new information is entered then that should be added in the table and sizecombID should be updated with highest value + 1. So for example if there is only one record in table as shown above then once a new combination is entered, my stored procedure should return 2..

can anybody help on this...

One possibility:

Code Snippet

SELECT SizeCombID

FROM MyTable

WHERE ( Col1 = NewValue1

AND Col2 = NewValue2

AND Col3 = NewValue3

)

IF ( @.@.ROWCOUNT = 0 )

INSERT INTO MyTable

( Col1,

Col2,

Col3

)

VALUES

( NewValue1,

NewValue2,

NewValue3

)

|||

Actually the code snippet is only checking 1 record which is not the case.

1. I will be sending all the entered records to my stored procedure, what is the parameter to be used for sending multiple records

2. All records entered by user are to be checked. In exmaple which was provided, user has entered four sizes so it will be four records. All four records are to be checked.

3. Can you also tell how i can increment the sizecombid automatically to generate next value. Before Insert statement, stored procedure should get the last sizecombID value, add 1 in it and then add that value also to SizecombID.

Pls advs..

|||

1.Passing Multiple Records:

Use XML string, you can get back those records in same structure you want.
There is no limitation since you can use either text or ntext as parameter datatype.

(Ex)

Code Snippet

Declare @.Param as Varchar(8000);
Select @.param = '<Root>
<Row Size="S" pieces="1" sizeID="1" sizecombID="1"/>
<Row Size="M" pieces="3" sizeID="2" sizecombID="1"/>
<Row Size="L" pieces="3" sizeID="3" sizecombID="1"/>
<Row Size="XL" pieces="1" sizeID="4" sizecombID="1"/>
</Root>'


Declare @.iDoc as Int;
EXEC sp_xml_preparedocument @.iDoc OUTPUT, @.param;


SELECT *
FROM OPENXML (@.idoc, '/Root/Row',1)
WITH (Size varchar(10),
pieces Int,
sizeID Int,
sizecombID Int)

EXEC sp_xml_removedocument @.iDoc;

2. You can store the xml result in Table variable and you can validate those with your main tables.

(ex)

Code Snippet

Declare @.Input table
(
Size varchar(10),
pieces Int,
sizeID Int,
sizecombID Int
);
insert Into @.Input
SELECT *
FROM OPENXML (@.idoc, '/Root/Row',1)
WITH (Size varchar(10),
pieces Int,
sizeID Int,
sizecombID Int)

3. This can be achived Max(id) + 1 but you have to take care the concurrent users issue.

|||

appreicate your reply on this, i have few more questions :-

1. Is xml the only way to acheive this, can't I pass a set of rows directly to stored procedure without using xml.

2. once all the records are available inside stored proc, do i have to loop through all records using cursor or temp table or i can get the results directly through a sql statement

3. I also thought of Max(id) but bcos of concurrency issues, i was hesitant. Can you suggest any other way ? i just want the value unique not necessarily it should be in sequence (i don't want to use guid)

4. Do you think that i should change my table structure to make it as a xml field for sizes instead of multiple rows, just wanted to know some suggestion on that..

5. how do u get these code snippet blocks in your post, these are very nice.

|||

1. No SQL Server wont support parameter as array value - it should be csv or xml

2. You can get the results directly from the SQL, most of the cursor used batches we can rewrite using SQL queries.

3. Then you can have a lookup table to fetch the unique id (SizeCombo Master table with Identity value) insert the new sizecombo on master table then use the @.@.IDENTITY / SCOPE_IDENTITY on your other detailed table.

4. Don't store your data as XML it will be very difficult to maintaine & manupulations , store the data as rows

5. Its there in the forum text editor itself (next to the Smily Icon with green color {})

|||

Hopefully last question..

Regarding answer to point 2, can u pls provide me the sql query which can search and return sizecombID from a table...

Monday, March 19, 2012

Check File size before importing

I have a DTS procedure that runs 4 times a day. It has worked well until
now. It is reading infromation from a text file. Today the text file was
empty and DTS failed giving me this error; "The volume for a file has been
externally altered so that the opened file is no longer valid.". I believe
this is happening because the file size is 0 K bytes (This file is
constantly overwriitten). Is there a way before importing a text file to
check and verify that the file is not empty?
Use FSO (File System Object) to check the size first in an ActiveX script,
you can find an exampl on sqldts.com
"deheinz1" <deheinz1@.discussions.microsoft.com> wrote in message
news:5292E0B2-B1B5-4B3F-A51C-45E66D8F0C53@.microsoft.com...
>I have a DTS procedure that runs 4 times a day. It has worked well until
> now. It is reading infromation from a text file. Today the text file was
> empty and DTS failed giving me this error; "The volume for a file has been
> externally altered so that the opened file is no longer valid.". I
> believe
> this is happening because the file size is 0 K bytes (This file is
> constantly overwriitten). Is there a way before importing a text file to
> check and verify that the file is not empty?
|||Even confirming that the file size is > 0 may not indicate reliably that the
source data transfer has completed. I have a similar situation where files
are being FTP'd from the mainframe and can take 1/2 or more to complete
(assuming they do complete). My solution was to ask the data processing
staff to download the file with an extention of .TMP and then rename it to
..DAT after the download is complete.
"deheinz1" <deheinz1@.discussions.microsoft.com> wrote in message
news:5292E0B2-B1B5-4B3F-A51C-45E66D8F0C53@.microsoft.com...
> I have a DTS procedure that runs 4 times a day. It has worked well until
> now. It is reading infromation from a text file. Today the text file was
> empty and DTS failed giving me this error; "The volume for a file has been
> externally altered so that the opened file is no longer valid.". I
believe
> this is happening because the file size is 0 K bytes (This file is
> constantly overwriitten). Is there a way before importing a text file to
> check and verify that the file is not empty?

Check File size before importing

I have a DTS procedure that runs 4 times a day. It has worked well until
now. It is reading infromation from a text file. Today the text file was
empty and DTS failed giving me this error; "The volume for a file has been
externally altered so that the opened file is no longer valid.". I believe
this is happening because the file size is 0 K bytes (This file is
constantly overwriitten). Is there a way before importing a text file to
check and verify that the file is not empty?Use FSO (File System Object) to check the size first in an ActiveX script,
you can find an exampl on sqldts.com
"deheinz1" <deheinz1@.discussions.microsoft.com> wrote in message
news:5292E0B2-B1B5-4B3F-A51C-45E66D8F0C53@.microsoft.com...
>I have a DTS procedure that runs 4 times a day. It has worked well until
> now. It is reading infromation from a text file. Today the text file was
> empty and DTS failed giving me this error; "The volume for a file has been
> externally altered so that the opened file is no longer valid.". I
> believe
> this is happening because the file size is 0 K bytes (This file is
> constantly overwriitten). Is there a way before importing a text file to
> check and verify that the file is not empty?|||Even confirming that the file size is > 0 may not indicate reliably that the
source data transfer has completed. I have a similar situation where files
are being FTP'd from the mainframe and can take 1/2 or more to complete
(assuming they do complete). My solution was to ask the data processing
staff to download the file with an extention of .TMP and then rename it to
.DAT after the download is complete.
"deheinz1" <deheinz1@.discussions.microsoft.com> wrote in message
news:5292E0B2-B1B5-4B3F-A51C-45E66D8F0C53@.microsoft.com...
> I have a DTS procedure that runs 4 times a day. It has worked well until
> now. It is reading infromation from a text file. Today the text file was
> empty and DTS failed giving me this error; "The volume for a file has been
> externally altered so that the opened file is no longer valid.". I
believe
> this is happening because the file size is 0 K bytes (This file is
> constantly overwriitten). Is there a way before importing a text file to
> check and verify that the file is not empty?

Check Disk Size in SQL 2000

I was wondering if there is a way to check the total disk size using
SQL 2000. There is a function to check how much is left, but havnt
found anything to check total size.Hi
I am not sure what you mean by this! You can look at the output of sp_helpdb
or sp_helpfile to get the file sizes of the databases and you can do this for
each database using a cursor! There are also SQL Server related permon
counters to monitor file sizes as well as perfmon counters to monitor disc
space usage. You can set an alert using perfmon if you disc usage reaches a
threshold. Alternatively you could use MOM to monitor your systems.
HTH
John
"cpatel1@.gmail.com" wrote:
> I was wondering if there is a way to check the total disk size using
> SQL 2000. There is a function to check how much is left, but havnt
> found anything to check total size.
>

Check Disk Size in SQL 2000

I was wondering if there is a way to check the total disk size using
SQL 2000. There is a function to check how much is left, but havnt
found anything to check total size.Hi
I am not sure what you mean by this! You can look at the output of sp_helpdb
or sp_helpfile to get the file sizes of the databases and you can do this fo
r
each database using a cursor! There are also SQL Server related permon
counters to monitor file sizes as well as perfmon counters to monitor disc
space usage. You can set an alert using perfmon if you disc usage reaches a
threshold. Alternatively you could use MOM to monitor your systems.
HTH
John
"cpatel1@.gmail.com" wrote:

> I was wondering if there is a way to check the total disk size using
> SQL 2000. There is a function to check how much is left, but havnt
> found anything to check total size.
>

Wednesday, March 7, 2012

Check Actual DB Size

Hi,
How do I check what is the actual DB size that is currently being use?
e.g. I set 10 GB as initial size. A few days and a few transactions later, how can I know how much was used since it is still under 10GB and checking the physical DB file will not tell me anything.If you are looking for SQL SERVER.
I think when u create it for the first time it creates a database of 2 GB.

If Enterprise Manager, select the Database name that you are looking for.
Right Click and check for Properties.

You get 2 Options : Size : 2 GB
Size Available : 0.98 GB.

Is this the Information that you are looking for|||ooh..okay..thanks...
But anybody can confirm that I just need to check from there?

I checked one of the db...the available size was 0.00mb but the Size is 40mb....this db was originally detach and ziped from Production enviroment and unziped then attached to Development.

Sunday, February 19, 2012

Chart auto-resizing problem

Hi - does anyone know how to stop a chart auto-sizing? I need the chart to
stay the same size. At the moment, depending on what data is graphed, the
y-axis auto-sizes so the chart window becomes bigger.Have you tried opening the chart properties dialog and setting explicit
values for the Y-axis minimum / maximum property?
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"baldgeezer" <baldgeezer@.ntlworld.com> wrote in message
news:srIFe.9301$9r6.8482@.news.cpqcorp.net...
> Hi - does anyone know how to stop a chart auto-sizing? I need the chart to
> stay the same size. At the moment, depending on what data is graphed, the
> y-axis auto-sizes so the chart window becomes bigger.
>|||Yes I've set that (e.g. 0 - 100) but depending on the data graphed, the
physical size of the axis enlarges although the scale remains 0-100.
"Robert Bruckner [MSFT]" <robruc@.online.microsoft.com> wrote in message
news:OM25$eykFHA.1440@.TK2MSFTNGP14.phx.gbl...
> Have you tried opening the chart properties dialog and setting explicit
> values for the Y-axis minimum / maximum property?
> -- Robert
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> "baldgeezer" <baldgeezer@.ntlworld.com> wrote in message
> news:srIFe.9301$9r6.8482@.news.cpqcorp.net...
>> Hi - does anyone know how to stop a chart auto-sizing? I need the chart
>> to
>> stay the same size. At the moment, depending on what data is graphed, the
>> y-axis auto-sizes so the chart window becomes bigger.
>|||The vertical space available for the y-axis also depends on the length/space
needed for the x-axis labels. Unless you ensure the x-axis labels use a
similar amount of space (e.g. by restricting the string length of x-axis
labels) for various data values, the y-axis height may change.
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"baldgeezer" <baldgeezer@.ntlworld.com> wrote in message
news:8%0Ge.9409$as7.5397@.news.cpqcorp.net...
> Yes I've set that (e.g. 0 - 100) but depending on the data graphed, the
> physical size of the axis enlarges although the scale remains 0-100.
>
> "Robert Bruckner [MSFT]" <robruc@.online.microsoft.com> wrote in message
> news:OM25$eykFHA.1440@.TK2MSFTNGP14.phx.gbl...
>> Have you tried opening the chart properties dialog and setting explicit
>> values for the Y-axis minimum / maximum property?
>> -- Robert
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>> "baldgeezer" <baldgeezer@.ntlworld.com> wrote in message
>> news:srIFe.9301$9r6.8482@.news.cpqcorp.net...
>> Hi - does anyone know how to stop a chart auto-sizing? I need the chart
>> to
>> stay the same size. At the moment, depending on what data is graphed,
>> the
>> y-axis auto-sizes so the chart window becomes bigger.
>>
>

Sunday, February 12, 2012

Changing the width of table column based on data returned

I would like to size the width of a table column to be big enough for the
data being returned. I don't seem to be able to use and expression for the
width parameter. How might I dynamically resize the with of table columns?THere is a property of a textbox which will allow its size to grow to fit
the text value... Just check the box...
--
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
"Greg Larsen" <GregLarsen@.discussions.microsoft.com> wrote in message
news:D3F216B4-9589-44D6-96F4-4F55DBFB34DE@.microsoft.com...
>I would like to size the width of a table column to be big enough for the
> data being returned. I don't seem to be able to use and expression for
> the
> width parameter. How might I dynamically resize the with of table
> columns?|||Greg,
The only thing I've seen so far in all my playing around is a height
increase/decrease, not a width version. Rightclick the field in question,
and choose properties. On the first tab is "Can increase to accomodate
contents" and "Can decrease to accomodate contents". I don't know why MS
doesn't have a dynamic width increase. Maybe the Dev team didn't put it in
so it wouldn't mess with the column structure.
Catadmin
"Greg Larsen" wrote:
> I would like to size the width of a table column to be big enough for the
> data being returned. I don't seem to be able to use and expression for the
> width parameter. How might I dynamically resize the with of table columns?

Friday, February 10, 2012

Changing value of "Initial Size (MB)"

I would like to increase the initial size of a SQL 2005 DB from 150 to 250 GB to prevent automatic autogrowth; would this have any impact in production if you do it on the fly?
Thanks,
Carlosyes it will ... sql server has to prepare the additional dataspace before it can be used. Why don;t you wait until off hours or a maintenance window?|||we have an equallogic iSCSI SAN and a 64 bit quad processor server. How much downtime should I plan for?

Thanks|||I would test it and see but you should be measuring in minutes - a real finger in the air maybe 10 minutes - but I really don't know. You could also maybe try doing it a bit at a time in a loop with a WAITFOR pause. This would prolong the process but maybe give the server chance to catch up on queued processes.

A further, more sophisticated method, would be to have a regular job check the amount of unused space at your typical low usage time (assuming there is one) and have it grow it ~3-4 days worth of growth if the free space is below a specified amount. This is the sort of proactive sizing we do in our shop.