Showing posts with label format. Show all posts
Showing posts with label format. Show all posts

Wednesday, March 28, 2012

Return all records in 15 min intervals.

Hello All,

First off thanks to all who try to help me.

I have a table with a date timestamp that includes the minute in 24 hour format..
I need to return all the records in the date range between '1/1/2007' and '1/31/2007' which is very simple.
The part I am having a hard time with is in the where clause.
I retrieve all the records for the date range into a #temptable
Now I need to sort these into 15 minute intervals based on the timestamp, but the sproc does'nt get passed a time only two dates also I need to provide a count of the records returned.

I have tried to create a temp table with 96 records being that there are 96 intervals of 15 minutes in 24 hours.
and using that as kinda a join.

I have tried to do something with datediff(_) with a dateadd(_)+15 in the where clause.

I also tried a loop 96 times.

I know there are a few ways to do it.I just dont know which ones.

I've only been using tsql for 2 months and have come pretty far, but this situation evades me.

Please enlighten me with your infinite wisdom of the tsql language. Help !

Is this the idea?

declare @.sampleData table
( rid integer primary key,
sampleDate datetime
)

insert into @.sampleData
select iter,
cast ('12/25/6' as datetime) + 70 * dbo.rand()
from small_iterator (nolock) -- A table of integers 1-32767

select top 5
rid,
sampleDate,
p.startOfInterval,
p.endOfInterval
from @.sampleData a
inner join
( select iter,
cast ((iter-1) * cast (cast ('0:15:00.000' as datetime) as float) as datetime)
as startOfInterval,
cast (iter * cast (cast ('0:15:00.000' as datetime) as float) as datetime)
as endOfInterval
from small_iterator (nolock) -- a table of integers 1-32767
where iter <= 96
) p
on sampleDate >= '1/1/7'
and sampleDate < '2/1/7'
and cast(cast(sampleDate as binary(4)) as datetime) >= p.startOfInterval
and cast(cast(sampleDate as binary(4)) as datetime) < p.endOfInterval
order by rid

-- rid sampleDate startOfInterval endOfInterval
-- -- - -
-- 1 2007-01-02 14:58:52.183 1900-01-01 14:44:59.997 1900-01-01 15:00:00.000
-- 3 2007-01-30 08:00:32.787 1900-01-01 08:00:00.000 1900-01-01 08:15:00.000
-- 4 2007-01-16 19:59:58.257 1900-01-01 19:45:00.000 1900-01-01 19:59:59.997
-- 5 2007-01-04 10:34:13.883 1900-01-01 10:30:00.000 1900-01-01 10:44:59.997
-- 8 2007-01-22 08:14:12.333 1900-01-01 08:00:00.000 1900-01-01 08:15:00.000


select left(convert (varchar(8), p.startOfInterval, 108), 5) as startOfInterval,
left(convert (varchar(8), p.endOfInterval, 108), 5) as endOfInterval,
count(*) as intervalCount
from @.sampleData a
inner join
( select iter,
cast ((iter-1) * cast (cast ('0:15:00.000' as datetime) as float) as datetime)
as startOfInterval,
cast (iter * cast (cast ('0:15:00.000' as datetime) as float) as datetime)
as endOfInterval
from small_iterator (nolock) -- a table of integers 1-32767
where iter <= 96
) p
on sampleDate >= '1/1/7'
and sampleDate < '2/1/7'
and cast(cast(sampleDate as binary(4)) as datetime) >= p.startOfInterval
and cast(cast(sampleDate as binary(4)) as datetime) < p.endOfInterval
group by p.startOfInterval, p.endOfInterval
order by p.StartOfInterval

-- startOfInterval endOfInterval intervalCount
-- - -
-- 00:00 00:15 151
-- 00:15 00:30 158
-- 00:30 00:45 134
-- ...
-- 23:30 23:44 145
-- 23:44 00:00 158

|||

Getting Closer..

Thank you very much Kent.
I wish I could write code like that in Tsql and actually "Get it to work" for me.

I need the data to look like this which for the most part the above does.

Date 1/1/2007 <Whatever user chooses

Time Interval Number Calls

12:00 12:15 147
12:15 12:30 117
12:30 12:45 215

The existing data I have looks like this for the timestamp field.

12/22/2003 9:29:00 AM
1/5/2004 1:31:00 PM
7/2/2003 3:53:00 PM
7/7/2003 1:27:00 PM


I have thought about parsing out the strings then back converting them but with sql we shouldnt have to do that.
I'm going to attempt to plug the above code in and see what I can do with it. More suggestions are welcome !

|||Do you need me to post my dbo.rand() function and small_iterator table?|||

You could change the SELECT list to that shown below.

Displaying the date above the output results (i.e. handling presentation) isn't what SQL Server is good at. It's far better to handle this in the client code or in Reporting Services.

Chris

SELECT CAST(DATEPART(hh, p.startOfInterval) AS VARCHAR(2)) + ':'

+ CAST(DATEPART(mi, p.startOfInterval) AS VARCHAR(2)) + ' '

+ CAST(DATEPART(hh, e.endOfInterval) AS VARCHAR(2)) + ':'

+ CAST(DATEPART(mi, e.endOfInterval) AS VARCHAR(2)) AS [Time Interval],

COUNT(*) AS [Number Calls]

|||

Kent - I know you weren't talking to me, but it would be good if you could. I've noticed you use small_iterator in a number of your posts.

Is it just a table of sequential integers?

Cheers
Chris

|||

Yes, small_iterator is a list of integers 1-32767; stand by and I will post this stuff. Here is another shot at your summary (the SMALL_ITERATOR and dbo.rand() will follow in a minute):

declare @.searchDate datetime
set @.searchDate = '3/1/7'

declare @.sampleData table
( rid integer primary key,
sampleDate datetime
)

insert into @.sampleData
select iter,
cast ('12/25/6' as datetime) + 70 * dbo.rand()
from small_iterator (nolock) -- A table of integers 1-32767


select left(convert (varchar(8), p.startOfInterval, 108), 5) + ' ' +
left(convert (varchar(8), p.endOfInterval, 108), 5) + ' ' as [ Time Interval],
count(*) as intervalCount
from @.sampleData a
inner join
( select iter,
cast ((iter-1) * cast (cast ('0:15:00.000' as datetime) as float) as datetime)
as startOfInterval,
cast (iter * cast (cast ('0:15:00.000' as datetime) as float) as datetime)
as endOfInterval
from small_iterator (nolock) -- a table of integers 1-32767
where iter <= 96
) p
on sampleDate >= @.searchDate
and sampleDate < (@.searchDate + 1)
and cast(cast(sampleDate as binary(4)) as datetime) >= p.startOfInterval
and cast(cast(sampleDate as binary(4)) as datetime) < p.endOfInterval
group by p.startOfInterval, p.endOfInterval
order by p.StartOfInterval

-- Time Interval intervalCount
-- -- -
-- 00:00 00:15 4
-- 00:15 00:30 6
-- 00:30 00:45 6
-- ...
-- 23:30 23:44 2
-- 23:44 00:00 2

|||

Here is my small_iterator table; it is simply a table of numbers. To get some ideas about tables of numbers, give this website a look:

http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-numbers-table.html

create table dbo.SMALL_ITERATOR
( iter smallint not null
constraint PK_SMALL_ITERATOR primary key
)
go


/* -- */
/* This routine is used to populate the small_iterator table. */
/* This query ran in 1 second in development and should run at */
/* a similar speed in production. */
/* -- */

truncate table SMALL_ITERATOR

insert into small_iterator
select number from master.dbo.spt_values (nolock)
where name is null
and number <= 255

insert into small_iterator
select 256 * j.iter + i.iter
from small_iterator i
inner join small_iterator j
on j.iter > 0
and j.iter <= 127
order by 256 * j.iter + i.iter

delete from small_iterator where iter = 0

select count(*) [count],
min (iter) [min iterator],
max (iter) [max iterator]
from SMALL_ITERATOR

go

dbcc dbreindex (small_iterator, '', 100)
go

update statistics small_iterator
go

exec sp_recompile small_iterator
go

|||

Here is my RAND scalar UDF; it comes in handy at times for generating mock data:

create view dbo.vRand
as
select rand () as vRand
go

create function dbo.rand ()
returns float
as
begin

return (select vRand from dbo.vRand)

end

go

create function dbo.randList
( @.pm_listSize integer
)
returns @.randList table
( rid integer,
iRand float
)
as
begin

declare @.upperBound integer

set @.upperBound = ceiling (convert(float, (@.pm_listSize+1))
/ convert (float, 32767))

insert into @.randList
select 32767*(j.iter-1) + i.iter - 1 as rid,
dbo.rand() as iRand
from small_iterator i (nolock)
inner join small_iterator j (nolock)
on j.iter <= @.upperBound
and 32767*(j.iter-1) + i.iter - 1 <= @.pm_listSize
and 32767*(j.iter-1) + i.iter - 1 > 0


return

end

go

|||

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=81913&SiteID=1

declare @.interval int
set @.interval=30

select dateadd(minute,floor(datediff(minute,0,OrderDate)/@.interval)*@.interval,0) [dt],
count(*) [cnt]
from Northwind..Orders
group by dateadd(minute,floor(datediff(minute,0,OrderDate)/@.interval)*@.interval,0)
order by 1

This is looking like it's going to work for my needs just have to tweak it a bit more..

Thanks to all who helped. One day I'll be able to help with tsql instead of just VB and ASP

Monday, March 26, 2012

Retruning Stored XML in a XML EXPLICIT statement

I have data stored in the database in XML format.

The data looks like this...

<entries><entry name = "Scott" /></entries>

When I return it using an xml explicit statement, it is return like this...

"Scott" /></entries>"/>

Is there a way to force it to use the normal tags instead of sql changing it?SELECT * FROM table for xml auto, elements

Friday, March 23, 2012

Retrieving XML Data

I know that I can retrieve table data in XML format, but is there a way to
retrieve data that is STORED as XML in a column as if it was relational
data?Michael Bray wrote:
> I know that I can retrieve table data in XML format, but is there a way to
> retrieve data that is STORED as XML in a column as if it was relational
> data?
Use the nodes method on the XML column, see BOL:
<URL:http://msdn2.microsoft.com/en-us/library/ms188282.aspx>
Martin Honnen -- MVP XML
http://JavaScript.FAQTs.com/

Monday, March 12, 2012

Retrieving Data in XML Format

Hi,
I use nested loop with inner joins to retrieve organization's chart from
EmployeeID-ReportsTo columns.
Our client uses XML and I must send the chart in XML format. How can I
perform this?
Any help would be greatly appreciated.
Leila
Did you look at the details about FOR XML clause in SQL Server Books Online?
Anith
|||Thanks Anith,
But I couldn't use FOR XML for my problem. When I query the sub-employees of
a particular employee, I must keep that in XML format. Then each
sub-employee may have sub-employees itself that should be inserted beneath
the related element.
Maybe I'm using wrong algorithm?
Please help me..
Thanks in advance..
"Anith Sen" <anith@.bizdatasolutions.com> wrote in message
news:uU#JCFr5EHA.3648@.TK2MSFTNGP11.phx.gbl...
> Did you look at the details about FOR XML clause in SQL Server Books
Online?
> --
> Anith
>
|||You will need to do this in your client tool. I suggest you post to a
newsgroup that supports whatever client application you are using.
Bob Barrows
Leila wrote:[vbcol=seagreen]
> Thanks Anith,
> But I couldn't use FOR XML for my problem. When I query the
> sub-employees of a particular employee, I must keep that in XML
> format. Then each sub-employee may have sub-employees itself that
> should be inserted beneath the related element.
> Maybe I'm using wrong algorithm?
> Please help me..
> Thanks in advance..
>
> "Anith Sen" <anith@.bizdatasolutions.com> wrote in message
> news:uU#JCFr5EHA.3648@.TK2MSFTNGP11.phx.gbl...
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Retrieving Data in XML Format

Hi,
I use nested loop with inner joins to retrieve organization's chart from
EmployeeID-ReportsTo columns.
Our client uses XML and I must send the chart in XML format. How can I
perform this?
Any help would be greatly appreciated.
LeilaDid you look at the details about FOR XML clause in SQL Server Books Online?
--
Anith|||Thanks Anith,
But I couldn't use FOR XML for my problem. When I query the sub-employees of
a particular employee, I must keep that in XML format. Then each
sub-employee may have sub-employees itself that should be inserted beneath
the related element.
Maybe I'm using wrong algorithm?
Please help me..
Thanks in advance..
"Anith Sen" <anith@.bizdatasolutions.com> wrote in message
news:uU#JCFr5EHA.3648@.TK2MSFTNGP11.phx.gbl...
> Did you look at the details about FOR XML clause in SQL Server Books
Online?
> --
> Anith
>|||You will need to do this in your client tool. I suggest you post to a
newsgroup that supports whatever client application you are using.
Bob Barrows
Leila wrote:
> Thanks Anith,
> But I couldn't use FOR XML for my problem. When I query the
> sub-employees of a particular employee, I must keep that in XML
> format. Then each sub-employee may have sub-employees itself that
> should be inserted beneath the related element.
> Maybe I'm using wrong algorithm?
> Please help me..
> Thanks in advance..
>
> "Anith Sen" <anith@.bizdatasolutions.com> wrote in message
> news:uU#JCFr5EHA.3648@.TK2MSFTNGP11.phx.gbl...
>> Did you look at the details about FOR XML clause in SQL Server Books
>> Online?
>> --
>> Anith
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Retrieving by months only

I have records in a table and 1 column is in the smalldatetime format which stores the date in the format "2004-09-22",2004-09-20",2004-09-12",2004-08-04" etc etc.

Can anyone tell me how to craft an SQL statement so that i can retrieve records for a certain month.For example,if i want to retrieve records for the month of September,i would get "2004-09-22",2004-09-20",2004-09-12" in results.SELECT * FROM yourTable WHERE
MONTH(ColumnName) = 9

Tuesday, February 21, 2012

retrieve Datetime

I have a table with a column tradedate of type datetime in which date
is stored in the format
mm/dd/yyyy hh:mm:sssAM. How do I retrieve this using Java resultset
I tried data, time and timestamp but I do not seem to get the exact
format. Any ideas?
Thanks a lot!No, your date is NOT stored in that format. If the column is defined as
datetime, it uses an internal format that you never see. The way it gets
displayed is determined by a number of factors, including your client
settings. If you want date to be displayed a certain way, use the CONVERT
function, and specify a format code, which is documented along with the
CONVERT function in the Books Online.
For full details on datetime storage, display and manipulation, please see:
http://www.karaszi.com/sqlserver/info_datetime.asp
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"db-x" <rashmi.ndeshpande@.gmail.com> wrote in message
news:1165512612.451830.77090@.79g2000cws.googlegroups.com...
>I have a table with a column tradedate of type datetime in which date
> is stored in the format
> mm/dd/yyyy hh:mm:sssAM. How do I retrieve this using Java resultset
> I tried data, time and timestamp but I do not seem to get the exact
> format. Any ideas?
> Thanks a lot!
>|||I had to use
convert(char(25),trade_date,131)
That was very helpful. Thank you!
Kalen Delaney wrote:
> No, your date is NOT stored in that format. If the column is defined as
> datetime, it uses an internal format that you never see. The way it gets
> displayed is determined by a number of factors, including your client
> settings. If you want date to be displayed a certain way, use the CONVERT
> function, and specify a format code, which is documented along with the
> CONVERT function in the Books Online.
> For full details on datetime storage, display and manipulation, please see:
> http://www.karaszi.com/sqlserver/info_datetime.asp
>
> --
> HTH
> Kalen Delaney, SQL Server MVP
> http://sqlblog.com
>
> "db-x" <rashmi.ndeshpande@.gmail.com> wrote in message
> news:1165512612.451830.77090@.79g2000cws.googlegroups.com...
> >I have a table with a column tradedate of type datetime in which date
> > is stored in the format
> > mm/dd/yyyy hh:mm:sssAM. How do I retrieve this using Java resultset
> > I tried data, time and timestamp but I do not seem to get the exact
> > format. Any ideas?
> >
> > Thanks a lot!
> >

Retrieve date from filename

Hye all,

I need help on this.

Let say my source file in excel format. Currently i'm using foreach loop to execute those source files. The problem is that , i want to retrieve a date from the source(filename) itself. i've tried using derived column. but it doesnt work.

eg: Source file name Email_Jan_05.xls, i want to grab the string JAN and 05 which later i'm going to put it in my database.

any suggestion? Thanks in advance.

Inside foreach loop, insert a script task before the data flow task, create a presedence constraint between them. Inside the script task, obtain the file date and store it in some variable.|||

Thanks Michael.

Anyway, do u have any source code / syntax or reference for this?

|||I don't have any code at hand, but look at System.IO.File.GetCreationTime and System.IO.File.GetLastWriteTime (depending on what time you need).

Retrieve and write

Hello,
I'm trying to retrieve data from Sql Server 2000 in XML format and HTTP it
to a gateway. And write the response in XML from gateway back to SQL Server.
Can anyone please advice me which is the best way to do it?
Thanks
ReddYou have three options with SQL Server 2000:
1. Take a look at the SQLXML component (version 3.0 is available for free
download from msd.microsoft.com). This provides you with an ISAPI extension.
2. Write your own web service and use the SQLXML component and the database
functionality (FOR XML, OpenXML and stored procs) using either ASP or
ASP.Net.
3. Use one of the third party tools.
Best regards
Michael
"Redd" <Redd@.discussions.microsoft.com> wrote in message
news:FD9F7B95-58E9-4955-B23B-3A8DC005512C@.microsoft.com...
> Hello,
> I'm trying to retrieve data from Sql Server 2000 in XML format and HTTP it
> to a gateway. And write the response in XML from gateway back to SQL
> Server.
> Can anyone please advice me which is the best way to do it?
> Thanks
> Redd|||Thanks Michael,
Your reply was very helpful. Since I'm new to SQL - XML mechanism, I have
couple more questions if you don't mind.
1. When I generate an XML output from SQLSERVER 2000 how can I HTTP it to
another server.
2. When I get the XML response from the server where would the XML file
reside and how can I access it to write data back into my database.
I would be very greatful to you I you can help me out with this.
Thanks
Redd
"Michael Rys [MSFT]" wrote:

> You have three options with SQL Server 2000:
> 1. Take a look at the SQLXML component (version 3.0 is available for free
> download from msd.microsoft.com). This provides you with an ISAPI extensio
n.
> 2. Write your own web service and use the SQLXML component and the databas
e
> functionality (FOR XML, OpenXML and stored procs) using either ASP or
> ASP.Net.
> 3. Use one of the third party tools.
> Best regards
> Michael
> "Redd" <Redd@.discussions.microsoft.com> wrote in message
> news:FD9F7B95-58E9-4955-B23B-3A8DC005512C@.microsoft.com...
>
>|||And also could you please let me know how to add root elements(which are not
in my database) to XML output using stored procedure.
For example:
my XML output file looks like this when I retrieve data from SQLSERVER 2000
using XML AUTO, ELEMENTS
<GHI>
<JKL>
<MNO>
.....
.....
</MNO>
</JKL>
</GHI>
Now I want to add:
<?XML VERSION=.........?>
<ABC>
<DEF>
<GHI>
.......
.......
</GHI>
</DEF>
</ABC>
How can I add <ABC>, <DEF> elements for each <GHI> element
Any idea would help
Thanks
Redd
"Redd" wrote:
> Thanks Michael,
> Your reply was very helpful. Since I'm new to SQL - XML mechanism, I have
> couple more questions if you don't mind.
> 1. When I generate an XML output from SQLSERVER 2000 how can I HTTP it to
> another server.
> 2. When I get the XML response from the server where would the XML file
> reside and how can I access it to write data back into my database.
> I would be very greatful to you I you can help me out with this.
> Thanks
> Redd
> "Michael Rys [MSFT]" wrote:
>|||The three options I give you below are the ways to "HTTP the XML to another
server". You need to make your database server accessible through HTTP by
using one of these 3 approaches (see their documentation for more details on
how to set up the ISAPI for example). Using the SQLXML 3.0 ISAPI and the
SQLXML templates is probably the approach that gives you the quickest way to
doing it.
Since HTTP is a stateless protocol that transport everything (well, in its
most basic form), the XML will be part of the response payload over HTTP
(similar to how you would get the HTML from a webserver). So you would get
the XML into your other application. You then do your changes and you will
have to communicate your changes back. Again, there are a couple of ways to
do it:
1. You can use the SQLXML 3.0 updategrams. This works if your model fits the
model of the updategrams.
2. You keep track of your changes and only send changes back against the
relational data.
3. You send the whole XML document back and use stored procs to perform the
change analysis (using OpenXML).
Again, you can expose this through an HTTP based service (e.g., a SQLXML
template or a stored proc).
Best regards
Michael
"Redd" <Redd@.discussions.microsoft.com> wrote in message
news:E468C8D6-730E-4576-98F8-C9456CB904AF@.microsoft.com...
> Thanks Michael,
> Your reply was very helpful. Since I'm new to SQL - XML mechanism, I have
> couple more questions if you don't mind.
> 1. When I generate an XML output from SQLSERVER 2000 how can I HTTP it to
> another server.
> 2. When I get the XML response from the server where would the XML file
> reside and how can I access it to write data back into my database.
> I would be very greatful to you I you can help me out with this.
> Thanks
> Redd
> "Michael Rys [MSFT]" wrote:
>|||Adding the XML declaration (<?xml ... ?> ) is not needed assuming the data
you are getting is in the right output encoding (which you can set on the
provider). Also you can set the root node property on the OLEDB, ADO and
ADO.Net providers that will add the root element around the fragment.
The property should be described in the SQLXML documentation.
Best regards
Michael
"Redd" <Redd@.discussions.microsoft.com> wrote in message
news:0C8C2554-C69E-4E29-992F-D02E2BC61FFF@.microsoft.com...
> And also could you please let me know how to add root elements(which are
> not
> in my database) to XML output using stored procedure.
> For example:
> my XML output file looks like this when I retrieve data from SQLSERVER
> 2000
> using XML AUTO, ELEMENTS
> <GHI>
> <JKL>
> <MNO>
> ......
> ......
> </MNO>
> </JKL>
> </GHI>
> Now I want to add:
> <?XML VERSION=.........?>
> <ABC>
> <DEF>
> <GHI>
> ........
> ........
> </GHI>
> </DEF>
> </ABC>
> How can I add <ABC>, <DEF> elements for each <GHI> element
> Any idea would help
> Thanks
> Redd
> "Redd" wrote:
>

Retrieve and write

Hello,
I'm trying to retrieve data from Sql Server 2000 in XML format and HTTP it
to a gateway. And write the response in XML from gateway back to SQL Server.
Can anyone please advice me which is the best way to do it?
Thanks
Redd
You have three options with SQL Server 2000:
1. Take a look at the SQLXML component (version 3.0 is available for free
download from msd.microsoft.com). This provides you with an ISAPI extension.
2. Write your own web service and use the SQLXML component and the database
functionality (FOR XML, OpenXML and stored procs) using either ASP or
ASP.Net.
3. Use one of the third party tools.
Best regards
Michael
"Redd" <Redd@.discussions.microsoft.com> wrote in message
news:FD9F7B95-58E9-4955-B23B-3A8DC005512C@.microsoft.com...
> Hello,
> I'm trying to retrieve data from Sql Server 2000 in XML format and HTTP it
> to a gateway. And write the response in XML from gateway back to SQL
> Server.
> Can anyone please advice me which is the best way to do it?
> Thanks
> Redd
|||Thanks Michael,
Your reply was very helpful. Since I'm new to SQL - XML mechanism, I have
couple more questions if you don't mind.
1. When I generate an XML output from SQLSERVER 2000 how can I HTTP it to
another server.
2. When I get the XML response from the server where would the XML file
reside and how can I access it to write data back into my database.
I would be very greatful to you I you can help me out with this.
Thanks
Redd
"Michael Rys [MSFT]" wrote:

> You have three options with SQL Server 2000:
> 1. Take a look at the SQLXML component (version 3.0 is available for free
> download from msd.microsoft.com). This provides you with an ISAPI extension.
> 2. Write your own web service and use the SQLXML component and the database
> functionality (FOR XML, OpenXML and stored procs) using either ASP or
> ASP.Net.
> 3. Use one of the third party tools.
> Best regards
> Michael
> "Redd" <Redd@.discussions.microsoft.com> wrote in message
> news:FD9F7B95-58E9-4955-B23B-3A8DC005512C@.microsoft.com...
>
>
|||And also could you please let me know how to add root elements(which are not
in my database) to XML output using stored procedure.
For example:
my XML output file looks like this when I retrieve data from SQLSERVER 2000
using XML AUTO, ELEMENTS
<GHI>
<JKL>
<MNO>
......
......
</MNO>
</JKL>
</GHI>
Now I want to add:
<?XML VERSION=.........?>
<ABC>
<DEF>
<GHI>
........
........
</GHI>
</DEF>
</ABC>
How can I add <ABC>, <DEF> elements for each <GHI> element
Any idea would help
Thanks
Redd
"Redd" wrote:
[vbcol=seagreen]
> Thanks Michael,
> Your reply was very helpful. Since I'm new to SQL - XML mechanism, I have
> couple more questions if you don't mind.
> 1. When I generate an XML output from SQLSERVER 2000 how can I HTTP it to
> another server.
> 2. When I get the XML response from the server where would the XML file
> reside and how can I access it to write data back into my database.
> I would be very greatful to you I you can help me out with this.
> Thanks
> Redd
> "Michael Rys [MSFT]" wrote:
|||The three options I give you below are the ways to "HTTP the XML to another
server". You need to make your database server accessible through HTTP by
using one of these 3 approaches (see their documentation for more details on
how to set up the ISAPI for example). Using the SQLXML 3.0 ISAPI and the
SQLXML templates is probably the approach that gives you the quickest way to
doing it.
Since HTTP is a stateless protocol that transport everything (well, in its
most basic form), the XML will be part of the response payload over HTTP
(similar to how you would get the HTML from a webserver). So you would get
the XML into your other application. You then do your changes and you will
have to communicate your changes back. Again, there are a couple of ways to
do it:
1. You can use the SQLXML 3.0 updategrams. This works if your model fits the
model of the updategrams.
2. You keep track of your changes and only send changes back against the
relational data.
3. You send the whole XML document back and use stored procs to perform the
change analysis (using OpenXML).
Again, you can expose this through an HTTP based service (e.g., a SQLXML
template or a stored proc).
Best regards
Michael
"Redd" <Redd@.discussions.microsoft.com> wrote in message
news:E468C8D6-730E-4576-98F8-C9456CB904AF@.microsoft.com...[vbcol=seagreen]
> Thanks Michael,
> Your reply was very helpful. Since I'm new to SQL - XML mechanism, I have
> couple more questions if you don't mind.
> 1. When I generate an XML output from SQLSERVER 2000 how can I HTTP it to
> another server.
> 2. When I get the XML response from the server where would the XML file
> reside and how can I access it to write data back into my database.
> I would be very greatful to you I you can help me out with this.
> Thanks
> Redd
> "Michael Rys [MSFT]" wrote:
|||Adding the XML declaration (<?xml ... ?>) is not needed assuming the data
you are getting is in the right output encoding (which you can set on the
provider). Also you can set the root node property on the OLEDB, ADO and
ADO.Net providers that will add the root element around the fragment.
The property should be described in the SQLXML documentation.
Best regards
Michael
"Redd" <Redd@.discussions.microsoft.com> wrote in message
news:0C8C2554-C69E-4E29-992F-D02E2BC61FFF@.microsoft.com...[vbcol=seagreen]
> And also could you please let me know how to add root elements(which are
> not
> in my database) to XML output using stored procedure.
> For example:
> my XML output file looks like this when I retrieve data from SQLSERVER
> 2000
> using XML AUTO, ELEMENTS
> <GHI>
> <JKL>
> <MNO>
> ......
> ......
> </MNO>
> </JKL>
> </GHI>
> Now I want to add:
> <?XML VERSION=.........?>
> <ABC>
> <DEF>
> <GHI>
> ........
> ........
> </GHI>
> </DEF>
> </ABC>
> How can I add <ABC>, <DEF> elements for each <GHI> element
> Any idea would help
> Thanks
> Redd
> "Redd" wrote:

Retrieve and display image inside an html file (stored in database) in binary format

Hi All,

I am not sure whether this is the right place to post this question. But I am unable to figure out what is the best solution to retrieve and display an image in a html file(stored in varbinary(max) column). I have a list of images in the file and I am supposed to display them. Can anybody please let me know what is the best way to do this?

Thanks a lot!!

HTML image links need to point to a URL. This means you can't just insert the image into the web form. If you have the images stored in a database, you will need to add another web page that will act like the image.

All you'll need in the new webpage is some code to get the image from the database as a byte array. Then write that out that image in the On_PageLoad as follows:

 
Dim img()As Byte' You'll need to add a function that will load the image into the byte array. It will pass in the id passed through the URL. img=LoadImage(Request.QueryString("id"))' Output the image and set the content type to jpeg Response.ContentType ="image/jpeg" Response.Expires = -1 Response.BinaryWrite(img) Response.End()

If the above was in a page called getImage.aspx you could link to it like this

<img src="http://pics.10026.com/?src=getImage.aspx?id=2" />

Hopefully that can get you pointed in the right direction. Let us know if you have any other questions.