Monday, February 27, 2012

Help writing a querry

I need some help with the following
I have a view as follow
date ValueIndex Value
20060131 2001 0.0455
20060130 2001 0.0455
20060129 2001 0.0454
20060128 2001 0.0453
20060127 2001 0.0453
20060126 2001 0.0452
20060125 2001 0.0452
20060124 2001 0.0451
20060123 2001 0.0451
20060122 2001 0.045
I would like to import a file with the date and the ValueIndex once I import
that file I would like to do a look up and get the value.
Is this possiable
Thanks
Chris>> I would like to import a file with the date and the ValueIndex once I
Yes, it is possible. What exactly do you find it difficult in doing it?
Importing the file to a table? Or writing the query to get the value?
Anith|||Anith,
Both -- I have no idea where to start
Please HELP!!!!!
"Anith Sen" wrote:

> Yes, it is possible. What exactly do you find it difficult in doing it?
> Importing the file to a table? Or writing the query to get the value?
> --
> Anith
>
>|||First of all, to get the data from a file to an SQL table, you have several
options.
Perhaps the easiest one is using DTS. Check out the topic Data
Transformation Services in the SQL Server Books Online. A simple interface
in SQL Enterprise Manager can get the job done.
Alternatively, you can use command line utilities like BCP or use BULK
INSERT to get the data from a file to the table. Again, you have all the
information needed in SQL Server Books Online.
To extract the desired data from an SQL table, you issue a query, generally
in the form of a SELECT statement. Given that your table has the columns
date_column, value_index & value with date_column as the primary key, you
could retrieve the value by using a SELECT statement like:
SELECT value FROM tbl WHERE date_column = @.param ;
-- where @.param is the parameter passed to the query to look up the desired
value.
All details needed for writing SQL can be found in SQL Server Books Online.
Anith|||Anith,
Thank you for your helpfull information.
After looking at the db I do not need to import the table it is already in
the db. I need to add a column to the table/view and populate that column
with the value base on the date and valueindex combination
Thank You
"Anith Sen" wrote:

> First of all, to get the data from a file to an SQL table, you have severa
l
> options.
> Perhaps the easiest one is using DTS. Check out the topic Data
> Transformation Services in the SQL Server Books Online. A simple interface
> in SQL Enterprise Manager can get the job done.
> Alternatively, you can use command line utilities like BCP or use BULK
> INSERT to get the data from a file to the table. Again, you have all the
> information needed in SQL Server Books Online.
> To extract the desired data from an SQL table, you issue a query, generall
y
> in the form of a SELECT statement. Given that your table has the columns
> date_column, value_index & value with date_column as the primary key, you
> could retrieve the value by using a SELECT statement like:
> SELECT value FROM tbl WHERE date_column = @.param ;
> -- where @.param is the parameter passed to the query to look up the desire
d
> value.
> All details needed for writing SQL can be found in SQL Server Books Online
.
> --
> Anith
>
>|||>> I need to add a column to the table/view
Look at ALTER TABLE .. ADD .. statement in SQL Server Books Online.
You can use an UPDATE statement, something along the lines of:
UPDATE tbl
SET value = ( SELECT t1.value FROM source_tbl t1
WHERE t1.date_col = tbl.date_col
AND t1.value_idx = tbl.value_idx )
WHERE EXISTS ( SELECT * FROM source_tbl t1
WHERE t1.date_col = tbl.date_col
AND t1.value_idx = tbl.value_idx );
For more details, lookup the topic UPDATE in SQL Server Books Online.
Anith|||A couple of links that may also help you understand the SQL...
http://www.w3schools.com/sql/sql_intro.asp
http://sqlzoo.net/
There are many others, but these both provide general walkthroughs of the
basics.
"Anith Sen" <anith@.bizdatasolutions.com> wrote in message
news:esd6BOLPGHA.1216@.TK2MSFTNGP14.phx.gbl...
> Look at ALTER TABLE .. ADD .. statement in SQL Server Books Online.
>
> You can use an UPDATE statement, something along the lines of:
> UPDATE tbl
> SET value = ( SELECT t1.value FROM source_tbl t1
> WHERE t1.date_col = tbl.date_col
> AND t1.value_idx = tbl.value_idx )
> WHERE EXISTS ( SELECT * FROM source_tbl t1
> WHERE t1.date_col = tbl.date_col
> AND t1.value_idx = tbl.value_idx );
> For more details, lookup the topic UPDATE in SQL Server Books Online.
> --
> Anith
>

No comments:

Post a Comment