Showing posts with label migrate. Show all posts
Showing posts with label migrate. Show all posts

Tuesday, March 20, 2012

Combine tables from previous db to new db (uhh...?)

I'm wanting to migrate an existing customer's database into a new products db. The previous contractor used seperate tables for each product type, where I chose to use one "products" table.

My challenge has been that the previous db uses attributes that aren't common across all products. Would it be best to do a products_attribute table? If so, how would I query the previous products db and seperate the information during an insert between "product A" and "product A attributes"?

Sample existing table:
ID, Name, Price, Weight, Attr1, Attr2, Attr3, Attr4, Attr5, Attr6

New table: Products
ID (auto), ProductName, Price, Weight
- Products_Attribute table
- ... ?you can use a cursor...and loop through each record...get the values into variables and insert into the 2 tables...

your products_attributes table can be somthing like

ID,Attr1, Attr2, Attr3, Attr4, Attr5, Attr6.... you can have the product name too if you need to..

HTH|||could you post a link or some example code for doing this? Thanks!|||sorry i misread your post...did u mean move data from one table in a DB to two tables in ANOTHER db ? or is this all within the same db ? if you are moving from one DB to another,then it wud be easier to move the entire table into the new db first and then separate the data into two tables inside the new db...

HTH|||from one source db to a different target db, then split into two tables at the target db.|||there are prbly many ways to do this...you can do the export/import wizard to transfer the table to the target db and then use tht table to split it..thts when you can use cursors to go through each row and insert the values into diff tables...

HTH|||Any links for cursor samples you're referring to? I haven't used them before.

Tuesday, February 14, 2012

column alias in where clause

Hi, I'm trying to migrate a database from Sybase to SQL Server. As far as I
understand (I'm not a db exert), it is not possible in SQL Server to
reference an alias for a column name that is defined in the select-clause in
the where clause. With Sybase this worked, so this kind of thing is widely
spread through the code. Just before I'm going to change all these alias
names to the actual column names: does someone know a way to avoid this,
which means using aliases in where clauses? While I'm at it: could it be the
case that 'IF' statements are not allowed in the select-clause?
Thanx in advance for all replies,
Martin
"Martin" schrieb:
> Hi, I'm trying to migrate a database from Sybase to SQL Server. As far as I
> understand (I'm not a db exert), it is not possible in SQL Server to
> reference an alias for a column name that is defined in the select-clause in
> the where clause. With Sybase this worked, so this kind of thing is widely
> spread through the code. Just before I'm going to change all these alias
> names to the actual column names: does someone know a way to avoid this,
> which means using aliases in where clauses? While I'm at it: could it be the
> case that 'IF' statements are not allowed in the select-clause?
> Thanx in advance for all replies,
> Martin
1. Aliases from the select list work in the where clause!
2. No 'if' in select statements, but 'case' does the trick ...
|||maybe I'm just doing it the wrong way, then (maybe the 'AS' is not really
what's meant by aliasing). But when I try:
SELECT My_ID, My_Some AS SomeAlias
FROM My_Table
WHERE (SomeAlias = 'a')
I get an "invalid colum name" error. I'll give the CASE a try, thanks!
"Christian Donner" wrote:

> "Martin" schrieb:
> 1. Aliases from the select list work in the where clause!
> 2. No 'if' in select statements, but 'case' does the trick ...
|||"Martin" schrieb:

> maybe I'm just doing it the wrong way, then (maybe the 'AS' is not really
> what's meant by aliasing). But when I try:
> SELECT My_ID, My_Some AS SomeAlias
> FROM My_Table
> WHERE (SomeAlias = 'a')
> I get an "invalid colum name" error. I'll give the CASE a try, thanks!
I'm terribly sorry! I mistook 'where' and 'order by' (I hope I will not be
banned from this forum for stupidity). Where clauses do NOT support aliases.
Sorry again for this blunder ...
|||Ok, so I have to rename those. Never mind the mix-up, after all, I got a
'positive' "It can't be done that way!"
"Christian Donner" wrote:

> "Martin" schrieb:
>
> I'm terribly sorry! I mistook 'where' and 'order by' (I hope I will not be
> banned from this forum for stupidity). Where clauses do NOT support aliases.
> Sorry again for this blunder ...
|||On Tue, 14 Jun 2005 02:29:01 -0700, Martin wrote:

>Hi, I'm trying to migrate a database from Sybase to SQL Server. As far as I
>understand (I'm not a db exert), it is not possible in SQL Server to
>reference an alias for a column name that is defined in the select-clause in
>the where clause. With Sybase this worked, so this kind of thing is widely
>spread through the code. Just before I'm going to change all these alias
>names to the actual column names: does someone know a way to avoid this,
>which means using aliases in where clauses? While I'm at it: could it be the
>case that 'IF' statements are not allowed in the select-clause?
>Thanx in advance for all replies,
>Martin
Hi Martin,
You can't use a column alias in the WHERE clause (or any other part of
the query, except ORDER BY). However, there is a workaround that uses
derived tables. This can be especially useful if a column in the SELECT
clause is defined using a lengthy expression and you don't feel like
repeating the expression. Simple example:
SELECT der.Expr1, der.Expr2,
der.Expr1 + der.Expr2,
der.Expr1 * der.Expr2
FROM (SELECT (insert lengtht expression here) AS Expr1,
(put another long expression here) AS Expr2
FROM MyTable
WHERE Col1 + Col2 < Col3) AS der
WHERE der.Expr1 BETWEEN der.Expr2 AND der.Expr2 * 2
AND der.Expr2 <> 0
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

Friday, February 10, 2012

Collation problem with SQL 2000

I need to migrate an application from SQL 7.0 to SQL 2000. I know
that they use different collations, and this causes problems when
7.0 applications are moved to 2000. I would like to find a
permanent fix (so I'm not happy with using "COLLATE" in future
stored procedures) and I'd like to keep the default 2000 collation
(Latin1_General_CI_AS) in order to avoid problems if the
application needs to be moved to another 2000 server in the future.
So the only option is to change the collation of the restored DB.
What is the most efficient way of doing this?
Thanks,

Marco"Marco" <mdi00@.hotmail.com> wrote in message
news:1106659656.008295.140310@.c13g2000cwb.googlegr oups.com...
>I need to migrate an application from SQL 7.0 to SQL 2000. I know
> that they use different collations, and this causes problems when
> 7.0 applications are moved to 2000. I would like to find a
> permanent fix (so I'm not happy with using "COLLATE" in future
> stored procedures) and I'd like to keep the default 2000 collation
> (Latin1_General_CI_AS) in order to avoid problems if the
> application needs to be moved to another 2000 server in the future.
> So the only option is to change the collation of the restored DB.
> What is the most efficient way of doing this?
> Thanks,
> Marco

ALTER DATABASE can change a database's collation, and ALTER TABLE can change
a single column's collation. I seem to remember changing the database's
collation once and discovering that it didn't change the collation of
existing tables, only new ones, so make sure you test properly first.

Simon|||Marco (mdi00@.hotmail.com) writes:
> I need to migrate an application from SQL 7.0 to SQL 2000. I know
> that they use different collations, and this causes problems when
> 7.0 applications are moved to 2000. I would like to find a
> permanent fix (so I'm not happy with using "COLLATE" in future
> stored procedures) and I'd like to keep the default 2000 collation
> (Latin1_General_CI_AS) in order to avoid problems if the
> application needs to be moved to another 2000 server in the future.
> So the only option is to change the collation of the restored DB.
> What is the most efficient way of doing this?

You will need to bulk out the data, build the database from scripts
and reload data.

But I would only do this if this agrees with business requirements. If
you don't have an SQL 2000 installation, you can install with the
collation of your preference. If there already is an SQL 2000 instance
on the box with a different collation, one option is to install a
second instance on the box.

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

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp