Showing posts with label line. Show all posts
Showing posts with label line. Show all posts

Friday, March 30, 2012

one line of results

I am trying to do a select statement where the results show up in one line like a,b,c,d,e...

I think I'm on the right track with the following code, but I have no idea what direction to go in. (I think my notes are not totally correct, but heck they're my notes. :-))

@.UM is getting wiped out after each into @.UM, how do I make it add to @.UM

declare @.UM varchar(3000) --declares variable
DECLARE abc CURSOR FOR --declares object for recordset
SELECT CONDCD FROM IBACOSTOCK GROUP BY CONDCD ORDER BY CONDCD
OPEN abc --stores results in recordset variable
FETCH NEXT FROM abc --grabs one line from recordset
INTO @.UM --stores line into variable
SELECT CONDCD FROM IBACOSTOCK GROUP BY CONDCD ORDER BY CONDCD
WHILE (@.@.FETCH_STATUS = 0) --as long as there are records in the recordset
begin
FETCH NEXT FROM abc --grabs next line from recordset
INTO @.UM --stores new line into variable
end
SELECT @.um
CLOSE abc --go back to while statement
DEALLOCATE abc --erase recordset
GOHow about...

DECLARE @.UM

SET @.UM = ''

SELECT @.UM = @.UM + CONDCD
FROM IBACOSTOCK
GROUP BY CONDCD ORDER BY CONDCD|||Yeah. I'm slow. I looked at my code afterwards and summed it up, and that's what I got. Thanks!

Monday, March 26, 2012

one line for 3 rows

for MS SQL 2000
I am having :
Table1
ID | N1 | N2 | N3 |
------
12 | A | | |
12 | | B| |
12 | | | C|
how can I get :
12,A,B,C ?
thank you for helpingselect id, max(n1), max(n2), max(n3) from Table1 group by id|||Thank you roac|||Just to ask a quick question : why is your table laid out like that?
I'm just curious to know if this can be related to a real world example.|||we are getting datas in this way from another application and we cannot change it
I am taking the datas to put them in another table to read them normally for our application|||what happens when you get more than 1 value in any given column?|||In what format is this other application giving you data? Is the application writing directly to your database?

If you are handling the data before it gets entered into your database then I would seriously reconsider a redesign of the table format and of the way you are inserting data. There is no normalisation here, which is half the point of a database structure.

I don't see why the data cannot just be written into one row:
i.e.

ID| N1|N2|N3
------
12 | A | B | C

Do you have a more meaningful example of the data you are using? What datatypes are you utilising?

on line idex rebuild

Hi

I am having sql server 2000 cluster and doing index rebuild every week

Now i am moving to SQL server 2005

Should i be going for online index rebuild?

what is the frequency i should be following?

Please advise

Thanks in advance

Hi,

You may go for online index rebuilding but before refer Index Rebuilding carefully ,some excerpts here from BOL:


Online Index Operations

When rebuilding an index and the ONLINE option is set to ON, the underlying objects, the tables and associated indexes, are available for queries and data modification. Exclusive table locks are held only for a very short amount of time during the alteration process.

Reorganizing an index is always performed online. The process does not hold locks long term and, therefore, does not block queries or updates that are running.

You can perform concurrent online index operations on the same table only when doing the following:

Creating multiple nonclustered indexes.

Reorganizing different indexes on the same table.

Reorganizing different indexes while rebuilding nonoverlapping indexes on the same table.

sql