Showing posts with label following. Show all posts
Showing posts with label following. Show all posts

Thursday, March 29, 2012

Echo sql which has been run

I am relatively new to SQL Server.

I have a command file with the following contents :
osql -E -i%1.sql -d%2 -oq:\%1.log

The sql script file has a number of insert/update statements.
The log file produced looks something like this :

1> 2> (1 row affected)
1> 2> (1 row affected)
1> 2> (0 rows affected)

Is there any setting which can be turned on such that the log file
produced from this command file will echo the statement and then
the number of rows which are affected.

TIA."Michael McGarrigle" <mjm@.barwonwater.vic.gov.au> wrote in message
news:9d0cafdc.0309111717.4dc8efaa@.posting.google.c om...
> I am relatively new to SQL Server.
> I have a command file with the following contents :
> osql -E -i%1.sql -d%2 -oq:\%1.log
> The sql script file has a number of insert/update statements.
> The log file produced looks something like this :
> 1> 2> (1 row affected)
> 1> 2> (1 row affected)
> 1> 2> (0 rows affected)
> Is there any setting which can be turned on such that the log file
> produced from this command file will echo the statement and then
> the number of rows which are affected.
> TIA.

You can try adding -e -n to your command line. It works best if each
statement is in its own batch:

update...
go
insert...
go

Like that, you get each statement with the rowcount immediately after it. If
all statements are in one batch, you'll get all the statements together then
all the rowcounts together. That might be OK for you anyway, of course.

Simonsql

Tuesday, March 27, 2012

Easy SQL query question

Hi,
I have a table (PartNumberTbl) includes all the part number.
I want to add a part number 'ALL' in the following output so that user
can select "ALL" in the DropDownList control:
SELECT DISTINCT (PartNumber) FROM PartNumberTbl WHERE Customer =
@.Customer
I don't want to create a Part Number "ALL" for each customer.
How to do it without create a temp table?
Or is there a better way to handle this?
Thanks,
BenConsider adding it to the client code so that the general query without part
number 'ALL' can be reused by several other applications. If all
applications require this entry as one of the rows, then consider using the
UNION operator.
Anith|||You can handle this at the client side of your application,
or, you can issue the following SELECT statement.
(Suppose that PartNumber is a char column.)
SELECT PartNumber
FROM PartNumberTbl
WHERE Customer = @.Customer
UNION
SELECT 'ALL' as PartNumber
Martin C K Poon
Senior Analyst Programmer
====================================
"Ben" <wubin_98@.yahoo.com> ?
news:1150146922.304849.52960@.c74g2000cwc.googlegroups.com ?...
> Hi,
> I have a table (PartNumberTbl) includes all the part number.
> I want to add a part number 'ALL' in the following output so that user
> can select "ALL" in the DropDownList control:
> SELECT DISTINCT (PartNumber) FROM PartNumberTbl WHERE Customer =
> @.Customer
> I don't want to create a Part Number "ALL" for each customer.
> How to do it without create a temp table?
> Or is there a better way to handle this?
> Thanks,
> Ben
>

Monday, March 26, 2012

Easy question

I generally do backups/restores of data and log files
using Enterprise Manager. I am just learning.
What does the following statement do?
BACKUP LOG YourDatabase WITH Truncate_Only
Like if take the backup from Enterprise it creates .bak
files whether the above statement will also create
some .bak files.That command truncates the inactive portion of the transaction log without
taking a transaction log backup. Good from reducing the size of the
transaction log, but since no backup was taken you will not be able to
restore any data that was added, deleted, or updated if those data
modifications where contained in the inactive portion of the transaction
that is truncated.
--
----
----
-
Need SQL Server Examples check out my website
http://www.geocities.com/sqlserverexamples
<anonymous@.discussions.microsoft.com> wrote in message
news:3fa501c49ffd$1dc02350$a301280a@.phx.gbl...
> I generally do backups/restores of data and log files
> using Enterprise Manager. I am just learning.
> What does the following statement do?
> BACKUP LOG YourDatabase WITH Truncate_Only
> Like if take the backup from Enterprise it creates .bak
> files whether the above statement will also create
> some .bak files.

Easy question

I generally do backups/restores of data and log files
using Enterprise Manager. I am just learning.
What does the following statement do?
BACKUP LOG YourDatabase WITH Truncate_Only
Like if take the backup from Enterprise it creates .bak
files whether the above statement will also create
some .bak files.
That command truncates the inactive portion of the transaction log without
taking a transaction log backup. Good from reducing the size of the
transaction log, but since no backup was taken you will not be able to
restore any data that was added, deleted, or updated if those data
modifications where contained in the inactive portion of the transaction
that is truncated.
----
-
Need SQL Server Examples check out my website
http://www.geocities.com/sqlserverexamples
<anonymous@.discussions.microsoft.com> wrote in message
news:3fa501c49ffd$1dc02350$a301280a@.phx.gbl...
> I generally do backups/restores of data and log files
> using Enterprise Manager. I am just learning.
> What does the following statement do?
> BACKUP LOG YourDatabase WITH Truncate_Only
> Like if take the backup from Enterprise it creates .bak
> files whether the above statement will also create
> some .bak files.

Easy query problem

Hello Experts-
I would like a sproc to return a 1 row select with results based on the
results of what it has found. For example say the following table were
created by the sp:
ID Name Dept
23 A 4
38 B 4
117 C 4
if the sproc could tell me which of these columns contained unique values
that would be great:
ID Name Dept
null null 4
In other words if all values in a column are the same, return that value,
otherwise return null.Select (Select Case When Count(*) = 1
Then Min(ID) Else Null End
From Table T
Group By ID) As ID,
(Select Case When Count(*) = 1
Then Min(Name) Else Null End
From Table T
Group By Name) As Name,
(Select Case When Count(*) = 1
Then Min(Dept) Else Null End
From Table T
Group By Dept) As Dept
"Coffee guy" wrote:

> Hello Experts-
> I would like a sproc to return a 1 row select with results based on the
> results of what it has found. For example say the following table were
> created by the sp:
> ID Name Dept
> 23 A 4
> 38 B 4
> 117 C 4
> if the sproc could tell me which of these columns contained unique values
> that would be great:
> ID Name Dept
> null null 4
> In other words if all values in a column are the same, return that value,
> otherwise return null.|||Sorry - messed that u.. Here's the right one...
Select (Select Case When Count(Distinct ID) = 1
Then Min(ID) Else Null End
From Table T) As ID,
(Select Case When Count(Distinct Name) = 1
Then Min(Name) Else Null End
From Table T) As Name,
(Select Case When Count(Distinct Dept) = 1
Then Min(Dept) Else Null End
From Table T) As Dept
"CBretana" wrote:
> Select (Select Case When Count(*) = 1
> Then Min(ID) Else Null End
> From Table T
> Group By ID) As ID,
> (Select Case When Count(*) = 1
> Then Min(Name) Else Null End
> From Table T
> Group By Name) As Name,
> (Select Case When Count(*) = 1
> Then Min(Dept) Else Null End
> From Table T
> Group By Dept) As Dept
>
> "Coffee guy" wrote:
>|||Coffee guy wrote:
> Hello Experts-
> I would like a sproc to return a 1 row select with results based on
> the results of what it has found. For example say the following
> table were created by the sp:
> ID Name Dept
> 23 A 4
> 38 B 4
> 117 C 4
> if the sproc could tell me which of these columns contained unique
> values that would be great:
> ID Name Dept
> null null 4
> In other words if all values in a column are the same, return that
> value, otherwise return null.
<snort>
What makes you think this query is "Easy"?
Try this:
CREATE TABLE #temp (
ID int,
Name varchar(10),
Dept int)
insert into #temp
select 23,'A',4
union all select 38,'B',4
union all select 117,'C',4
SELECT
(SELECT TOP 1 CASE WHEN
(SELECT COUNT(DISTINCT ID) FROM #temp)=1 THEN
ID
END FROM #temp) ID
,(SELECT TOP 1 CASE WHEN
(SELECT COUNT(DISTINCT Name) FROM #temp)=1 THEN
Name
END FROM #temp) Name
,(SELECT TOP 1 CASE WHEN
(SELECT COUNT(DISTINCT Dept) FROM #temp)=1 THEN
Dept
END FROM #temp) Dept
drop table #temp
Bob Barrows
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.|||Thanks to both, harder than I thought ;)
"Bob Barrows [MVP]" wrote:

> Coffee guy wrote:
> <snort>
> What makes you think this query is "Easy"?
> Try this:
> CREATE TABLE #temp (
> ID int,
> Name varchar(10),
> Dept int)
> insert into #temp
> select 23,'A',4
> union all select 38,'B',4
> union all select 117,'C',4
> SELECT
> (SELECT TOP 1 CASE WHEN
> (SELECT COUNT(DISTINCT ID) FROM #temp)=1 THEN
> ID
> END FROM #temp) ID
> ,(SELECT TOP 1 CASE WHEN
> (SELECT COUNT(DISTINCT Name) FROM #temp)=1 THEN
> Name
> END FROM #temp) Name
> ,(SELECT TOP 1 CASE WHEN
> (SELECT COUNT(DISTINCT Dept) FROM #temp)=1 THEN
> Dept
> END FROM #temp) Dept
> drop table #temp
> Bob Barrows
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>|||I think this is a bit simpler than what's been posted so far. Assuming
no NULLs in any of the columns,
select
case when min(ID) = max(ID) then min(ID) else null end as ID,
case when min(Name) = max(Name) then min(Name) else null end as Name,
case when min(Dept) = max(Dept) then min(Dept) else null end as Dept
from #temp
Steve Kass
Drew University
Coffee guy wrote:
>Thanks to both, harder than I thought ;)
>"Bob Barrows [MVP]" wrote:
>
>|||Duh! I definitely did not give this enough thought.
Thanks,
Bob
Steve Kass wrote:
> I think this is a bit simpler than what's been posted so far. Assuming no
> NULLs in any of the columns,
> select
> case when min(ID) = max(ID) then min(ID) else null end as ID,
> case when min(Name) = max(Name) then min(Name) else null end as Name,
> case when min(Dept) = max(Dept) then min(Dept) else null end as Dept
> from #temp
>
> Steve Kass
> Drew University
> Coffee guy wrote:
>
--
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"|||Steve,
Yes, Elegant !
"Steve Kass" wrote:

> I think this is a bit simpler than what's been posted so far. Assuming
> no NULLs in any of the columns,
> select
> case when min(ID) = max(ID) then min(ID) else null end as ID,
> case when min(Name) = max(Name) then min(Name) else null end as Name,
> case when min(Dept) = max(Dept) then min(Dept) else null end as Dept
> from #temp
>
> Steve Kass
> Drew University
> Coffee guy wrote:
>
>|||And if your fingers are tired, these are a tiny bit shorter,
but they're basically the same thing:
select
nullif(min(ID),nullif(min(ID), max(ID))) as ID,
nullif(min(Name),nullif(min(Name), max(Name))) as Name,
nullif(min(Dept),nullif(min(Dept), max(Dept))) as Dept
from #temp
select
case min(ID) when max(ID) then min(ID) end as ID,
case min(Name) when max(Name) then min(Name) end as Name,
case min(Dept) when max(Dept) then min(Dept) end as Dept
from #temp
SK
CBretana wrote:
>Steve,
>Yes, Elegant !
>
>"Steve Kass" wrote:
>
>sql

Easy query help

I want to perform the following query but i dont know how :

select count(num) from X

and I want the X to be a table from the following query :

select table from bla bla bla . . .

This cannot be done by :select count(num) from (select table from bla bla bla) !

How can i build it ? I have stuck !which database is this? because the method you described should work

what was the actual error message you got?

perhaps you could also show real table and column names so we could see if there is an obvious syntax error|||I get a incorrect synbtax :

The query is
select count(distinct timestamp) from (select cf.table from general_cfg cf, can c where cf.x1 = c.y1);

This should have worked ?|||no, it shouldn't've

the subquery produces an intermediate table result which is used as the data source for the outer query's FROM clause, yes?

well, that intermediate table result has a single column, called "table"

thus, the outer table cannot count the distinct values of a column called "timestamp" because that column doesn't exist|||Are we trying to sneak up on dynamic SQL here?

-PatP|||And is there a solution to this problem at last ...???|||yes there is!!!!!!!!!!!!|||select count(num) from (select table from bla bla bla)
Add an alias name for the table:select count(num) from (select num from table from bla bla bla) AS tmp

Easy One I hope - What to Use?

Hi
Need to create a report that needs to show the following:
# of results # of results >5 % of
results >5 Mean of
within 5 days days days
Results
Jan
Feb
March
April etc
What is the best dataregion to use?
CheersPlease check my response on your "matrix expression problem".
I would however think that using a table for this case is easier than using
a matrix.
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Nat Johnson" <NatJohnson@.discussions.microsoft.com> wrote in message
news:05BDB4B8-F927-4321-8D25-245BAEE443DA@.microsoft.com...
> Hi
> Need to create a report that needs to show the following:
> # of results # of results >5 % of
> results >5 Mean of
> within 5 days days
> days
> Results
> Jan
> Feb
> March
> April etc
>
> What is the best dataregion to use?
> Cheers

Thursday, March 22, 2012

Easy Convert Question

Will the following SQL allow me to see the results of the computed column in
decimal format even if the Columns used in the calculation are defind as int
:
Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) 'Count'
I have used it but I am not getting any decimal places. It is showing the
decimals as 0. If this is not the problem could you please make some
suggestions.
Thanks
AdamTry multiplying the arguments by 1.0, or explicitly converting the arguments
to decimal.
By arguments, I mean the individual pieces, not the result of the
calculation.
A
"A.B." <AB@.discussions.microsoft.com> wrote in message
news:836A42B5-D2D1-480B-82A5-A167007B0123@.microsoft.com...
> Will the following SQL allow me to see the results of the computed column
> in
> decimal format even if the Columns used in the calculation are defind as
> int:
> Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards]))
> 'Count'
> I have used it but I am not getting any decimal places. It is showing the
> decimals as 0. If this is not the problem could you please make some
> suggestions.
> Thanks
> Adam|||You have to change the formula instead.
((#Operator2.[Count] * 1000.00)/#Closed2.[Dyed Yards])
AMB
"A.B." wrote:

> Will the following SQL allow me to see the results of the computed column
in
> decimal format even if the Columns used in the calculation are defind as i
nt:
> Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) 'Count'
> I have used it but I am not getting any decimal places. It is showing the
> decimals as 0. If this is not the problem could you please make some
> suggestions.
> Thanks
> Adam|||Can you try this:
Convert(Dec(10,5), ((#Operator2.[Count]*1000.0)/#Closed2.[Dyed Yards]))
'Count'
Perayu
"A.B." wrote:

> Will the following SQL allow me to see the results of the computed column
in
> decimal format even if the Columns used in the calculation are defind as i
nt:
> Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) 'Count'
> I have used it but I am not getting any decimal places. It is showing the
> decimals as 0. If this is not the problem could you please make some
> suggestions.
> Thanks
> Adam|||How about something like this
select price/cast(code as money) from xyz
i.e. the denominator gets converted to 'money' type :)
Cheers,
JP (Just a programmer:))
--
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:O515emXqFHA.2652@.tk2msftngp13.phx.gbl...
> Try multiplying the arguments by 1.0, or explicitly converting the
> arguments to decimal.
> By arguments, I mean the individual pieces, not the result of the
> calculation.
> A
>
>
> "A.B." <AB@.discussions.microsoft.com> wrote in message
> news:836A42B5-D2D1-480B-82A5-A167007B0123@.microsoft.com...
>|||Thanks guys, it worked
"A.B." wrote:

> Will the following SQL allow me to see the results of the computed column
in
> decimal format even if the Columns used in the calculation are defind as i
nt:
> Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) 'Count'
> I have used it but I am not getting any decimal places. It is showing the
> decimals as 0. If this is not the problem could you please make some
> suggestions.
> Thanks
> Adam|||OR
select price/cast(code as decimal(10,4)) from xyz
Cheers,
JP (Just a Programmer;))
--
"JP" <someone@.somewhere.com> wrote in message
news:ucbhzwXqFHA.3104@.TK2MSFTNGP12.phx.gbl...
> How about something like this
> select price/cast(code as money) from xyz
> i.e. the denominator gets converted to 'money' type :)
> Cheers,
> JP (Just a programmer:))
> --
> "Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in
> message news:O515emXqFHA.2652@.tk2msftngp13.phx.gbl...
>|||hi AB
you can try it as:
#Operator2.[Count]*1000.0)/#Closed2.[Dyed Yards] as [count]
hope this will help u
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.SQLResource.com/
---
"A.B." wrote:

> Will the following SQL allow me to see the results of the computed column
in
> decimal format even if the Columns used in the calculation are defind as i
nt:
> Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) 'Count'
> I have used it but I am not getting any decimal places. It is showing the
> decimals as 0. If this is not the problem could you please make some
> suggestions.
> Thanks
> Adam

Wednesday, March 21, 2012

Dynamics GP Evaluation copy installation

Hi,

I am trying to install an evaluation copy of Dynamics GP on my laptop but it keeps giving me the following error:

msde failed to install. Return code 1603

Any idea what I need to do. I am not a techy so you'll have to be gentle with me.

Thanks

Raju

download

msde and install it before hand

http://www.microsoft.com/sql/prodinfo/previousversions/msde/download.mspx

Dynamics GP Evaluation copy installation

Hi,

I am trying to install an evaluation copy of Dynamics GP on my laptop but it keeps giving me the following error:

msde failed to install. Return code 1603

Any idea what I need to do. I am not a techy so you'll have to be gentle with me.

Thanks

Raju

download

msde and install it before hand

http://www.microsoft.com/sql/prodinfo/previousversions/msde/download.mspx

Dynamicly setting events

I have the following code and I'm trying to set an event dynamicly in the foreach statement...

SqlConnection

conn =newSqlConnection(ConfigurationManager.AppSettings["BvtQueueConnectString2"]);SqlCommand select =newSqlCommand("select top 100 b.jobid as [Job ID], bq.timesubmitted as [Time Submitted], b.timereceived as [Time Received], bq.requestid as [Request ID], bq.timecompleted as [Time Completed], bq.buginfoid as [Bug Info ID], e.eventid as [Event ID], bq.closingeventid as [Closing Event ID], et.eventtype as [Event Type], e.eventtime as [State Start Time], l.twolettercode as [Language], p.projectname as [Project Name], p.packagedesignation as [Package Designation] from bvtjobs b inner join bvtrequestsnew bq on b.jobid = bq.jobid inner join eventlog e on bq.requestid = e.bvtrequestid inner join eventtypes et on e.eventtype = et.eventtypeid inner join languages l on bq.targetlanguage = l.langid inner join projects p on bq.targetplatform = p.projectid order by b.jobid asc", conn);SqlDataAdapter da =newSqlDataAdapter(select);DataSet ds =newDataSet();

conn.Open();

da.Fill(ds);

conn.Close();

Table table =newTable();

foreach (DataRow drin ds.Tables[0].Rows)

{

TableRow tr =newTableRow();for (int i = 0; i < dr.ItemArray.Length; i++)

{

TableCell tc =newTableCell();

tc.Text = dr.ItemArray.GetValue(i).ToString();

tc.BackColor =

Color.White;if (dr.ItemArray.GetValue(8).ToString() =="COMPLETE")

{

tc.BackColor =

Color.BlueViolet;

}

tr.Cells.Add(tc);

}

table.Rows.Add(tr);

}

foreach (TableRow tablerowin table.Rows)

{

TableCell newtc =newTableCell();Button mybutton =newButton();

newtc.Controls.Add(mybutton);

mybutton.Text =

"details";

//set the event here

tablerow.Cells.Add(newtc);

}

Panel1.Controls.Add(table);

DataBind();

I am assuming you have added a button dynamically, and you want to create a handler for this button.

First you need to create a function to do what you want, e.g.

Sub myButtonClicked (sender, args)

....

End sub

Then you need to tell asp.net that this is the function to run when the button is clicked. In your code, before you add the button to the tablecell, write:

AddHandler myButton.click, AddressOg myButtonClicked

A little warning though - this may not work. This is because you have to create any dynamic controls everytime the page load. Have a read ofthis page which should help you.

|||

thanks for the response.

The solution that I have found is to add the eventhandler and specify what you want to do init. In this case redirect towww.google.com :

protected

void Page_Load(object sender,EventArgs e)

{

SqlConnection conn =newSqlConnection(ConfigurationManager.AppSettings["BvtQueueConnectString2"]);SqlCommand select =newSqlCommand("select top 100 b.jobid as [Job ID], bq.timesubmitted as [Time Submitted], b.timereceived as [Time Received], bq.requestid as [Request ID], bq.timecompleted as [Time Completed], bq.buginfoid as [Bug Info ID], e.eventid as [Event ID], bq.closingeventid as [Closing Event ID], et.eventtype as [Event Type], e.eventtime as [State Start Time], l.twolettercode as [Language], p.projectname as [Project Name], p.packagedesignation as [Package Designation] from bvtjobs b inner join bvtrequestsnew bq on b.jobid = bq.jobid inner join eventlog e on bq.requestid = e.bvtrequestid inner join eventtypes et on e.eventtype = et.eventtypeid inner join languages l on bq.targetlanguage = l.langid inner join projects p on bq.targetplatform = p.projectid order by b.jobid asc", conn);SqlDataAdapter da =newSqlDataAdapter(select);DataSet ds =newDataSet();

conn.Open();

da.Fill(ds);

conn.Close();

Table table =newTable();

foreach (DataRow drin ds.Tables[0].Rows)

{

TableRow tr =newTableRow();for (int i = 0; i < dr.ItemArray.Length; i++)

{

TableCell tc =newTableCell();

tc.Text = dr.ItemArray.GetValue(i).ToString();

tc.BackColor =

Color.White;if (dr.ItemArray.GetValue(8).ToString() =="COMPLETE")

{

tc.BackColor =

Color.BlueViolet;

}

tr.Cells.Add(tc);

}

table.Rows.Add(tr);

}

foreach (TableRow tablerowin table.Rows)

{

TableCell newtc =newTableCell();Button mybutton =newButton();

newtc.Controls.Add(mybutton);

mybutton.Text =

"details";

mybutton.Click +=

newEventHandler(mybutton_Click);

tablerow.Cells.Add(newtc);

}

Panel1.Controls.Add(table);

DataBind();

}

void mybutton_Click(object sender,EventArgs e)

{

Response.Redirect(

"http://www.google.com");

}

Sunday, March 11, 2012

Dynamically formatting data using XSD

Hi,
I am working on following requirement:
Data stored in a table (SQL Server 2005 database) needs to be retrieved
into a .Net application. The columns that need to be retrieved (the
schema) will be predefined by users. Data needs to be retrieved for
each user based on the schema defined by the user (The schema will
define columns and the order of the columns).
I am analyzing different options like storing the schema in database
(XML Schema collection) or in a physical file (XSD) and retrieving them
using XQuery. However, as the data is not stored as a XML data type,
the options are not working.
Any guidance, suggestions would be appreciated.
Thanks.
Regards,
Sameer
Hello Sameer,
I think you might be getting confused as to what a XSD Schema is, what an
XML Schema Collection is and Annotated XSD Schemas. It boils down to this:
an XSD schema is an XML document that can be used to describe and validate
another XML instance. An XML Schema Collection is a SQL Server 2005 concept
for storing the schemas that describe an XML instance. It consists of one
or XSD Schemas, usually on a per namespace basis. Neither of these directly
provide that you're looking for.
It sounds like what you are looking for is Annotated XSD Schemas. BOL does
a good job of covering these in the topic "Annotated XSD Schemas in SQLXML
4.0"
Thanks,
Kent
|||Thanks Kent.
Kent Tegels wrote:
> Hello Sameer,
> I think you might be getting confused as to what a XSD Schema is, what an
> XML Schema Collection is and Annotated XSD Schemas. It boils down to this:
> an XSD schema is an XML document that can be used to describe and validate
> another XML instance. An XML Schema Collection is a SQL Server 2005 concept
> for storing the schemas that describe an XML instance. It consists of one
> or XSD Schemas, usually on a per namespace basis. Neither of these directly
> provide that you're looking for.
> It sounds like what you are looking for is Annotated XSD Schemas. BOL does
> a good job of covering these in the topic "Annotated XSD Schemas in SQLXML
> 4.0"
> Thanks,
> Kent

Dynamically formatting data using XSD

Hi,
I am working on following requirement:
Data stored in a table (SQL Server 2005 database) needs to be retrieved
into a .Net application. The columns that need to be retrieved (the
schema) will be predefined by users. Data needs to be retrieved for
each user based on the schema defined by the user (The schema will
define columns and the order of the columns).
I am analyzing different options like storing the schema in database
(XML Schema collection) or in a physical file (XSD) and retrieving them
using XQuery. However, as the data is not stored as a XML data type,
the options are not working.
Any guidance, suggestions would be appreciated.
Thanks.
Regards,
SameerHello Sameer,
I think you might be getting as to what a XSD Schema is, what an
XML Schema Collection is and Annotated XSD Schemas. It boils down to this:
an XSD schema is an XML document that can be used to describe and validate
another XML instance. An XML Schema Collection is a SQL Server 2005 concept
for storing the schemas that describe an XML instance. It consists of one
or XSD Schemas, usually on a per namespace basis. Neither of these directly
provide that you're looking for.
It sounds like what you are looking for is Annotated XSD Schemas. BOL does
a good job of covering these in the topic "Annotated XSD Schemas in SQLXML
4.0"
Thanks,
Kent|||Thanks Kent.
Kent Tegels wrote:
> Hello Sameer,
> I think you might be getting as to what a XSD Schema is, what an
> XML Schema Collection is and Annotated XSD Schemas. It boils down to this:
> an XSD schema is an XML document that can be used to describe and validate
> another XML instance. An XML Schema Collection is a SQL Server 2005 concep
t
> for storing the schemas that describe an XML instance. It consists of one
> or XSD Schemas, usually on a per namespace basis. Neither of these directl
y
> provide that you're looking for.
> It sounds like what you are looking for is Annotated XSD Schemas. BOL does
> a good job of covering these in the topic "Annotated XSD Schemas in SQLXML
> 4.0"
> Thanks,
> Kent

dynamically delete data

Hi All,
I have the following situation.
Every month, I populate data from a source table.
This table has a field called process_date (char data type) and the
format is mmyy. So, 0406 means data for the month of April of 2006.
This source table always overlaps with old data. For example, for this
month it may have data for January, February or March of 2006, which I
already have processed.
What I do presently is I manually run a delete command and then insert
in the target table.
Such as:
delete Table1 where Process_Date<>'0406'
I want to make this automated so that I will not have to manually run
the above code.
I was wondering how could I achieve that?
I will highly appreciate your help.
Thanks a million in advance.
Best regards,
MamunHello Mamun,
You could create a SQL Server Agent job to run every month. This job
can execute the T-SQL statements you require to insert/delete the
required data and won't require any intervention by you (although you
should be checking that whenever the job executes it executes
successfully).
If you're new to creating SQL Server Agent jobs then SQL Server Books
Online should be able to run you through the process.
HTH,
Nate.
mamun wrote:
> Hi All,
> I have the following situation.
> Every month, I populate data from a source table.
> This table has a field called process_date (char data type) and the
> format is mmyy. So, 0406 means data for the month of April of 2006.
> This source table always overlaps with old data. For example, for this
> month it may have data for January, February or March of 2006, which I
> already have processed.
> What I do presently is I manually run a delete command and then insert
> in the target table.
> Such as:
> delete Table1 where Process_Date<>'0406'
> I want to make this automated so that I will not have to manually run
> the above code.
> I was wondering how could I achieve that?
> I will highly appreciate your help.
> Thanks a million in advance.
> Best regards,
> Mamun

Friday, March 9, 2012

Dynamically Changing the Picture at the Record Level.

Hi,
Appreciate your help on the following.
I need to display images according to the status of the record. For example,
I am displaying product list where the margin is less than 15% then display
image1, when margin is between 16% and 25% display image2 etc. I am currently
using a table to store the path of the images.
Thank you again,
KG@.SF
Highly appreciate your helpI also have to develop similar concept but Matrix report where I have to
again display image indicators when a category of product margin falls betwen
a certain range. Appreciate your help,
KG
"KG@.SFC" wrote:
> Hi,
> Appreciate your help on the following.
> I need to display images according to the status of the record. For example,
> I am displaying product list where the margin is less than 15% then display
> image1, when margin is between 16% and 25% display image2 etc. I am currently
> using a table to store the path of the images.
> Thank you again,
> KG@.SF
> Highly appreciate your help

Wednesday, March 7, 2012

Dynamic Where clause

What is the best way to dynamically choose the where clause based on a
variable.
In the following test example, depending on @.i value, WHERE clause could
compare against being null or not null.
Another way to do would be writing ugly sql string like @.select + @.where
Please let me know.
TIA...
set nocount on
go
create table z_test_del
(
c1 int,
c2 int
)
go
insert z_test_del values(1,null)
insert z_test_del values(2,333)
insert z_test_del values(3,null)
insert z_test_del values(4,5555)
go
declare @.i int
set @.i = 0
if (@.i = 0)
select * from z_test_del where c2 is null
else
select * from z_test_del where c2 is not null
go
drop table z_test_del
go>> What is the best way to dynamically choose the where clause based on a
variable. <<
Dynamic is poor choice of words in SQL -- it implies that you are
writing code on the fly.
SELECT *c1, c2 -- never use * in production code!!
FROM Foobar
WHERE (c2 IS NULL AND @.flag = 0)
OR (c2 IS NOT NULL AND @.flag <> 0);|||You can use a CASE or use OR-ed predicates or write two separate statements.
For some alternatives refer to: http://www.sommarskog.se/dyn-search.html
Anith|||Thanks Joe.
"--CELKO--" wrote:

> variable. <<
> Dynamic is poor choice of words in SQL -- it implies that you are
> writing code on the fly.
> SELECT *c1, c2 -- never use * in production code!!
> FROM Foobar
> WHERE (c2 IS NULL AND @.flag = 0)
> OR (c2 IS NOT NULL AND @.flag <> 0);
>

Sunday, February 26, 2012

dynamic update

i have a table with the following values

iden nam status
-- -- --
1 pp NULL
1 kk NULL
2 rr NULL
2 nn NULL
2 jj NULL
3 hh NULL

now i want to update the status cloumn in this table in such a way that the status colum = 'Status is' + iden + nam for all distinct values of iden from the table

how can we do this without using a cursor?

Here it is,

Code Snippet

Create Table #data (

[iden] int ,

[nam] Varchar(100) ,

[status] Varchar(100)

);

Insert Into #data Values('1','pp',NULL);

Insert Into #data Values('1','kk',NULL);

Insert Into #data Values('2','rr',NULL);

Insert Into #data Values('2','nn',NULL);

Insert Into #data Values('2','jj',NULL);

Insert Into #data Values('3','hh',NULL);

Update #data

Set

[status] = 'Status is ' + Cast(iden as varchar) + ' ' +nam

Select * from #data

|||

The most important question is why would you want to do that? It is both unnecessary, and not a good design consideration to store data that is easily 'computed' from existing row data.

Use a VIEW instead.

CREATE VIEW dbo.vMyTableView

AS

SELECT

Iden,

Nam,

[Status] = 'Status is ' + Cast( Iden as varchar(10) ) + Nam

FROM dbo.MyTable

GO

Friday, February 24, 2012

Dynamic Tablename

Hi,
Maybe a simple Question
I have a Dataset with following SQL Command:
SELECT a.*, b.stelleText
FROM verkauf_leas200510 a LEFT OUTER JOIN
Vregion_stelle b ON a.stellelevel = b.stelleLevel AND
a.stellekey = b.stelleKey
WHERE (a.stellelevel = @.pStelleLevel) AND (a.stellekey = @.pStelleKey)
ORDER BY a.stellelevel, a.stellekey, a.sort
Is it possible to change theTablename (verkauf_leas200510 ) also
dynamically, maybe also with a parameter like in the where-clause
Have not found a solution yet, because i want to generate a report with the
tablename as parameter.
Thanks in advance
DieterIf you can use a stored procedure as a datasource for the report you can
solve the problem by creating dynamic SQL.
The Proc will have 3 parameters:
@.Tablename
@.pStelleLevel
@.pStelleKey
And in the proc you will dynamically create the select statement
Grtz,
Nico
"Dieter Felix" wrote:
> Hi,
> Maybe a simple Question
> I have a Dataset with following SQL Command:
> SELECT a.*, b.stelleText
> FROM verkauf_leas200510 a LEFT OUTER JOIN
> Vregion_stelle b ON a.stellelevel = b.stelleLevel AND
> a.stellekey = b.stelleKey
> WHERE (a.stellelevel = @.pStelleLevel) AND (a.stellekey = @.pStelleKey)
> ORDER BY a.stellelevel, a.stellekey, a.sort
> Is it possible to change theTablename (verkauf_leas200510 ) also
> dynamically, maybe also with a parameter like in the where-clause
> Have not found a solution yet, because i want to generate a report with the
> tablename as parameter.
> Thanks in advance
> Dieter|||Table name is not a problem. However, you need to have the field names
returned stay the same. To do this have the query tool in generic mode. Then
you put in an expression
="select * from " & parameters!TableName.value
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Dieter Felix" <Dieter Felix@.discussions.microsoft.com> wrote in message
news:6D6DE04F-8F74-418E-9EB2-E32E7437F0E1@.microsoft.com...
> Hi,
> Maybe a simple Question
> I have a Dataset with following SQL Command:
> SELECT a.*, b.stelleText
> FROM verkauf_leas200510 a LEFT OUTER JOIN
> Vregion_stelle b ON a.stellelevel = b.stelleLevel AND
> a.stellekey = b.stelleKey
> WHERE (a.stellelevel = @.pStelleLevel) AND (a.stellekey = @.pStelleKey)
> ORDER BY a.stellelevel, a.stellekey, a.sort
> Is it possible to change theTablename (verkauf_leas200510 ) also
> dynamically, maybe also with a parameter like in the where-clause
> Have not found a solution yet, because i want to generate a report with
> the
> tablename as parameter.
> Thanks in advance
> Dieter

Sunday, February 19, 2012

dynamic sql with char(39)

hi,
What's the pros and cons for the following two methods
when you define charactor strings in a dynamic sql?
1.
SELECT @.EXPORT_VIEW_SQL = ... 'SELECT ' + char(39)
+ '000000' + char(39) ...
2.
SELECT @.EXPORT_VIEW_SQL = ... 'SELECT ' + ''000000'' ...
they both work, I personally prefer second method, what do
you think?
many thanks!!
JJ
I use the second method most of the time. But occassionally when I have
some complex and requires many single qoute, and I am having problems with
the quoting I will consider using the char(39).
----
-
Need SQL Server Examples check out my website
http://www.geocities.com/sqlserverexamples
"JJ Wang" <anonymous@.discussions.microsoft.com> wrote in message
news:455a01c4904c$370c3e40$a301280a@.phx.gbl...
> hi,
> What's the pros and cons for the following two methods
> when you define charactor strings in a dynamic sql?
> 1.
> SELECT @.EXPORT_VIEW_SQL = ... 'SELECT ' + char(39)
> + '000000' + char(39) ...
> 2.
> SELECT @.EXPORT_VIEW_SQL = ... 'SELECT ' + ''000000'' ...
> they both work, I personally prefer second method, what do
> you think?
> many thanks!!
> JJ
>
|||thanks Gregory! so there is no performance or reliability
difference between the two?
JJ
>--Original Message--
>I use the second method most of the time. But
occassionally when I have
>some complex and requires many single qoute, and I am
having problems with
>the quoting I will consider using the char(39).
>--
>----
--
>----
--
>-
>Need SQL Server Examples check out my website
>http://www.geocities.com/sqlserverexamples
>
>"JJ Wang" <anonymous@.discussions.microsoft.com> wrote in
message[vbcol=seagreen]
>news:455a01c4904c$370c3e40$a301280a@.phx.gbl...
+ ''000000'' ...[vbcol=seagreen]
do
>
>.
>
|||Or you can use this #3.
SELECT @.EXPORT_VIEW_SQL = 'SELECT ' + quotename('000000',char(39))
"JJ Wang" <anonymous@.discussions.microsoft.com> wrote in message
news:455a01c4904c$370c3e40$a301280a@.phx.gbl...
> hi,
> What's the pros and cons for the following two methods
> when you define charactor strings in a dynamic sql?
> 1.
> SELECT @.EXPORT_VIEW_SQL = ... 'SELECT ' + char(39)
> + '000000' + char(39) ...
> 2.
> SELECT @.EXPORT_VIEW_SQL = ... 'SELECT ' + ''000000'' ...
> they both work, I personally prefer second method, what do
> you think?
> many thanks!!
> JJ
>

dynamic sql statement error

Hi all
I would greatly appriciate your help in resolving the following error:
In t-sql procedure I am building a simple dynamic sql statement using
parametes.
Here is the code:
===========
step 0 - declare local variables:
--
declare @.localParam as datetime
declare @.strSelect as varchar(300)
declare @.colName as varchar(30)
step 1 - build the select statement with parameter:
---
set @.colName = 'OPENING_DATE'
set @.strSelect = 'select min('+ @.colName+ ') from dbo.DW_PURCHASE_U'
step 2 - set return value to a local parameter:
----
set @.strSelect = 'set @.localParam = ('
+ @.strSelect +
')'
step 3 - execute the statement and generate error!:
---
exec (@.strSelect)
Yelds the following error: 'Must declare the variable @.localParam ...
Why is @.localParam not recognized?
Changing it type to varchar did not make a diference nor using
sp_executesql.
If you have some other way to build this kind of dynamic sql statements
(which return some value to a
local param ) I'd be more than thank full.
Thanks for your help
ReaTry using sp_executesql:
DECLARE @.localParam as datetime
DECLARE @.strSelect as nvarchar(300)
DECLARE @.colName as sysname
set @.colName = 'OPENING_DATE'
SET @.strSelect = N'SELECT @.localParam =
MIN(' + @.colName + ') FROM dbo.DW_PURCHASE_U'
EXEC sp_executesql @.strSelect,
N'@.localParam datetime OUT',
@.localParam OUT
SELECT @.localParam
Hope this helps.
Dan Guzman
SQL Server MVP
"Rea Peleg" <rea_p@.afek.co.il> wrote in message
news:uxLedR0ZEHA.3112@.tk2msftngp13.phx.gbl...
> Hi all
> I would greatly appriciate your help in resolving the following error:
> In t-sql procedure I am building a simple dynamic sql statement using
> parametes.
> Here is the code:
> ===========
> step 0 - declare local variables:
> --
> declare @.localParam as datetime
> declare @.strSelect as varchar(300)
> declare @.colName as varchar(30)
> step 1 - build the select statement with parameter:
> ---
> set @.colName = 'OPENING_DATE'
> set @.strSelect = 'select min('+ @.colName+ ') from dbo.DW_PURCHASE_U'
> step 2 - set return value to a local parameter:
> ----
> set @.strSelect = 'set @.localParam = ('
> + @.strSelect +
> ')'
> step 3 - execute the statement and generate error!:
> ---
> exec (@.strSelect)
> Yelds the following error: 'Must declare the variable @.localParam ...
> Why is @.localParam not recognized?
> Changing it type to varchar did not make a diference nor using
> sp_executesql.
> If you have some other way to build this kind of dynamic sql statements
> (which return some value to a
> local param ) I'd be more than thank full.
> Thanks for your help
> Rea
>
>
>