Query To Represent Denormalization Of Data

May 22, 2007

Hi All,

Bit of a funny one. I have two tables, lets call them PetOwner and Pets


PetOwner

OwnerID OwnerName
1 Tim
2 Paul
3 Andy


Pets
OwnerID PetName
1 Tricia
1 Louise
2 Bill
2 Ben
2 David
2 Topsy
3 Flopsy
3 Mopsy

And I need to write a query that returns a resultset like this


OwnerID OwnerName PetName1 PetName2 PetName3 PetName4 PetName5
1 Tim Tricia Louise NULL NULL NULL
2 Paul Bill Ben David Topsy Flopsy
3 Andy Flopsy Mopsy NULL NULL NULL

Can anyone help?

N.B. A pet owner can only have a maximum of 5 pets, but even if no-one in the database has 5 pets, the PetName5 column must still appear (but have a value of NULL).

View 13 Replies


ADVERTISEMENT

Data Warehousing :: How To Represent Metadata In A Data Warehouse

Sep 24, 2015

I am working on to create a data warehouse. I have made a database which will be the data warehouse and will consist of dimension and fact tables. I know that other than dimension and fact table a data warehouse should also consist of a meta data, now my question is what should be the structure of metadata and all the information it should have?

View 2 Replies View Related

How/what Is Denormalisation Or Denormalization

Sep 1, 2006

Hi

I came accross recently the term denormalisation basically the article that i read in a magazine said after normalising a database you should follow "by tactical denormalisation to improve database performance."

My questions are:

- What is denormali(z/s)ation? (my understanding is after you normalise you go back in reverse using some sort of technique?)?

- Does it increase performance?

- can any one give example of how it can be used... where the performance is greater than the normalised way?

thanks

View 6 Replies View Related

Table Denormalization

Nov 20, 2007

I have a table that looks like this:

acct payment product product description
1 10.00 1 book
1 20.00 2 lamp
2 10.00 1 book
2 300.00 3 blackberry
2 60.00 4 drawer

how would i denormalize this table in t-sql so that it would look like this:

acct payment1 product1 product1 descr payment2 product2 product2 descr payment3 product3 product3 descr
1 10.00 1 book 20.00 2 lamp
2 10.00 1 book 300.00 3 blackberry 60.00 4 drawer

Thanks in advance.

View 6 Replies View Related

Denormalization, 2 Databases , 1 Read 1 Write Db

May 28, 2008

Hi,
I was reading that many of these high traffic websites actually have 2 databases, 1 database is used ONLY for reads, while the other is for writes.

How does one go about creating such a setup? How does the database where writes are allowed replicated the data to the read only database server?

View 1 Replies View Related

SQL 2012 :: How To Represent Servers CPU Utilization

May 30, 2014

I have multiple instances of SQL 2012 Std Edition on a 40 physical core server.What I have done is the use the Process - SQLServr -% Processor time Stat and divided by 16 ( the max number of Cores Std ed. can use) as a instance level measure. I also use processor object stats to show how busy the server is. How to represent the servers CPU utilization?

View 1 Replies View Related

Represent A Value List As A Table For Outer Join????

Jul 20, 2005

This might not be possible, but on the chance that it can - is there away to do the following:Given a arbitray one dimesional value list:('AALGX','12345','XXXXX','AAINX','AMMXX')Is there a way that I could do a select statement, or similiar, in thevalue list, to get the following resultfield_name-----------AALGX12345XXXXXAAINXAMMXXBecause, what I want to be able to do in the long run is essentiallyperform an outer join on the value list.Something along the lines ofselect value_list.field_name, dbtable.otherfield FROM value_list leftouter join dbtable on value_list.field_name = dbtable.field_nameSo I want all the values in the field list to show up, and anymatching data in the database table that exists, otherwise null.Maybe there is another approach to this???Thanks!KT

View 4 Replies View Related

Target String Size Is Too Small To Represent The XML Instance

Feb 7, 2006

This is a tough error....
The situation:  we are trying to manage Stored Procedures (ALTER, CREATE, DROP statements) on one of our SQL2005 servers and this error spews out:
"Target string size is too small to represent the XML instance"
Now this script i wrote (simple alter statement adding a column) works on 4 other versions of SQL 2005, but when i try a certain server, i get that error
Searching Google, Yahoo, and MSN, all three point to one single instance of this error, right here on Don Keily's blog
http://www.sqljunkies.com/WebLog/donkiely/archive/2005/10/20.aspx
 and unfortunately... no solution  :(
Maybe in the 3 months since that post, someone might have run across that and knows how to fix?

View 5 Replies View Related

Transact SQL :: Represent Time Interval Between 2 Date Columns

May 20, 2015

I have a simple table as shown:

I want to have values on the last column to represent the time interval between the 2 date columns (visits); i.e for event-ID 2 for example, I will have

entry(EventID = 2)  - exit(EventID = 1), and so on

View 7 Replies View Related

How To Represent Maximum Number Of Books Borrowed At Same Time Through A Trigger

Feb 20, 2013

I have to build a database model, create tables and use triggers or/and procedures on it. It's about a library. Books are borrowed by students. They can make a reservation of a book.

I built the database model so far. My problem is how to represent following tasks:

- Students can borrow a maximum of 5 books at the same time.
- bookings/book reservations should be later processed in the order they occurred. That is, who first flagged the book also gets the book/books first

I have following entities:

- Book
- Book exemplar
- Borrowed by (a table between the entities Book exemplar and Student)
- Reserved for (a table between the entities Book exemplar and Student)
- Student

How would you represent the tasks I mentioned above in terms of triggers or procedures?...

View 5 Replies View Related

SQL Server 2012 :: Create A Table That Would Represent Workload For Each Shop

Mar 19, 2015

I am trying to create a table that would represent a workload for each shop. In order to do that I need to have WorkLoad table and ShopWorkLoad table which is actually just aggregation of WorkLoad.

WorkLoad contains a list of following items:

current orders that are in the process (one select statement)
scheduled orders (another select statement)
expected orders (third select statement) that come through a third-party system

All of this needs to be live. So, for example, as soon as order is added to Order table it should be included in WorkLoad if certain conditions are met. Same goes for scheduled orders (which come from another table). Expected orders will be loaded on a daily bases (based on historical data).

ShopWorkLoad table is aggregation of WorkLoad table.

Currently I did it this way:

Added after insert/update trigger on Order table: when order is created/updated, if it meets certain conditions, it should be inserted in WorkLoad, otherwise remove it from workload if it's in there and doesn't meet conditions

Added after insert/update trigger on Schedule table: when order is scheduled, if it meets certain conditions, it should be inserted in WorkLoad, otherwise remove it from workload if it's in there and doesn't meet conditions

Running daily job that populates WorkLoad table with expected orders based on historical values

Final step is to create an indexed view vShopWorkLoad

My biggest concern is usage of triggers which call pretty complex logic to determine whether item should be added to workload or not.

One other option was to create vWorkLoad view and somehow make it an indexed view but currently I don't see a way of doing that because the query consists of 4 union select statements, below is pseudo example. But even if doing it that way, how to build aggregated indexed view on top of vWorkLoad indexed view?

Third option is to use sql agent job which would run every x seconds (maybe 20) and it would execute all of these queries to populate WorkLoad table with delay of 10-20 seconds, but I am still not sure if this is acceptable to the client.

Fourth option is to create 3 or 4 indexed view where sum of them makes a workload. Then, ShopWorkLoad view would be built on top of these 3 or 4 indexed views, but in this case I don't know how this would affect performance since ShopWorkLoad query would be often queried.

Example of workload pseudo query:

select
WorkLoadType = 'Order in process',
OrderId,
ShopId,
...
from
Order

[Code] ....

View 1 Replies View Related

Problem With Managed Code Simple Example Target String Size Is Too Small To Represent The XML Instance

Feb 10, 2006



I am trying to understand creating SQL Server projects and managed code. So I created a C# SQL Server Database project and named it "CSharpSqlServerProject1" and followed the steps in the following "How to: " from the Help files:

"How to: Create and Run a CLR SQL Server Stored Procedure "

I used the exact code in this "How to: " for creating a SQL Server managed code stored procedure (see below) in C#. However it didn't even compile! When I went to build the code I got the following error message:

"Error 1 Target string size is too small to represent the XML instance CSharpSqlServerProject1"

It does not give a line number or any further information! Since this is a Microsoft example I'm following I figure others must have run into this too. I can't figure out how to fix it!

Here's the code as copied directly from the howto:

using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;

public partial class StoredProcedures
{
[SqlProcedure()]
public static void InsertCurrency_CS(
SqlString currencyCode, SqlString name)
{
using (SqlConnection conn = new SqlConnection("context connection=true"))
{
SqlCommand InsertCurrencyCommand = new SqlCommand();

InsertCurrencyCommand.CommandText =
"insert Sales.Currency (CurrencyCode, Name, ModifiedDate)" +
" values('" + currencyCode.ToString() +
"', '" + name.ToString() +
"', '" + System.DateTime.Now.ToString() + "')";

InsertCurrencyCommand.Connection = conn;

conn.Open();
InsertCurrencyCommand.ExecuteNonQuery();
conn.Close();
}
}
}


Thanks for any help you can give!

View 7 Replies View Related

Opening Up Odbc Data Source In The Query Query Inside Of The Server Manager

Jun 15, 2007

I'm trying to find the command to open up an odbc conection inside sql2005 express. I only have ues of an odbc connector, we're conection to remedy. We will eventually be using stored procedures to extract the data we need from remedy and doing additional data crunching. I'm a foxpro programmer so once I get the correct syntax for making the odbc connector I shold be ok. Also I need a really good advanced book on sql2005. The type of book that would have my odbc answer. I've spent all morning trying to find this information and was unable to.



Thanks in advance



Daniel Buchanan.



If this was the wrong forum to post this on, please move this question to the correct one. I need this answer soon.

View 1 Replies View Related

Master Data Services :: Error - Query Processor Could Not Produce A Query Plan

Jul 19, 2015

We have a issue with a MDS server that have been over us for a couple of days, the original error msg from SQL Server Engine is the one "The query processor could not produce a query plan" but the ones we get on the Excel-Addin are "Sequece contains no elements" or "The value cannot be null" T

• Using Microsoft SQL Server 2012 (SP1) - 11.0.3393.0 (X64) for 6months on this server without issues

• Two weeks ago we started to have 2 errors: "Sequence Contains No Elements" | "The Value Cannot Be Null"

• We are using the last version of Excel Add-in

• We try to reinstall the MDS feature

• If I backup/restore MDS database to other server it works

• We updated to SQL 2012 SP2 + CU4 but the error persisted ...

Looking at the MDSTraceLog we are routed to the this msg

SQL Error Debug Info: Number: 8624, Message: Internal Query Processor Error: The query processor could not produce a query plan. For more information, contact Customer Support Services., Server: bbdvsql03inst01, Proc: udpMetadataEntityGetDetailsXML, Line: 28

At line 28 udpMetadataEntityGetDetailsXML is calling udfMetadataEntityGetDetailsXML … and here is where we stopped

** Error found when try to get data from a entity using Excel add-in **
===================================
Sequence contains no elements
------------------------------
Program Location:
   at Microsoft.MasterDataServices.AsyncEssentials.AsyncResultBase.EndInvoke()
   at Microsoft.MasterDataServices.ExcelAddInCore.AsyncProviderBase`1.EndOperation(IAsyncResult ar)

[code]....

View 3 Replies View Related

How To Query An Oracle Data From SQL Server Query Analyser

Sep 3, 2007



Hi ,

I am having 2 data store .
1. Oracle 10g
2 SQL server 2000

My requirement is that , i need to insert some data from sql server database table to oracle database using sql server query analyser or interface.


If there is any way ,plz let me know it


Thanks
Abraham

View 3 Replies View Related

Update Query Containg Static Data And Data From Another Table.

Sep 28, 2006

Hi,First post so apologies if this sounds a bit confusing!!I'm trying to run the following update. On a weekly basis i want toinsert all the active users ids from a users table into a timesheetstable along with the last day of the week and a submitted flag set to0. I plan then on creating a schduled job so the script runs weekly.The 3 queries i plan to use are below.Insert statement:INSERT INTO TBL_TIMESHEETS (TBL_TIMESHEETS.USER_ID,TBL_TIMESHEETS.WEEK_ENDING, TBL_TIMESHEETS.IS_SUBMITTED)VALUES ('user ids', 'week end date', '0')Get User Ids:SELECT TBL_USERS.USER_ID from TBL_USERS where TBL_USERS.IS_ACTIVE = '1'Get last date of the weekSELECT DATEADD(wk, DATEDIFF(wk,0,getdate()), 6)I'm having trouble combing them as i'm pretty new to this. Is the bestapproach to use a cursor?If you need anymore info let me know. Thanks in advance.

View 4 Replies View Related

Data Warehousing :: Query That Extracts Email Data From A Column

Jun 8, 2015

I have  a column in which Email data is available like 

clicuanan@aspenms.com(M)
jteply@mac.com(M)

How to extract in the below format

clicuanan@aspenms.com
jteply@mac.com
tjones@jpmc.com

View 4 Replies View Related

Data Access :: Query On View To Get A Single Batched Data

Nov 25, 2015

I have a view that  give me the data of all the batched. Now I am using a query on view to get a single batched data. when I am using direct query it was taking 0 sec but when I am using Through view "select *  from myView where batched=2" then its taking 30 mnt.

View 3 Replies View Related

SQL Search :: Query For Finding Two Columns Data In Third Column And Getting Data From It?

Jul 6, 2015

getting result as given below.

Input:

id Name Data

101 AA PQ102BBRAJAKIRANBUBLU

102 BB RS101AAEROJUCHALABAGUNDI

103 CC TU104GGANDICANKILLANYONE

OUTPUT:

id Name Data

101 AA 101AAEROJUCHALABAGUNDI

102 BB PQ102BBRAJAKIRANBUBLU

103 CC

View 4 Replies View Related

Change Data Table From System.data Into Sql Query

Apr 4, 2007

i someone had teach me how to write a query in datatable. however i need to get the data out from my database rather than the data table. can someone teach me how should i do it?esp at the first like.... like DataTable dt = GetFilledTable() since i already have set of data in my preset table i should be getting data from SqlDataSource1 right ( however i am writing this in my background code or within <script></script> so can anyone help me?   protected void lnkRadius_Click(object sender, EventArgs e)        {            DataTable dt = GetFilledTable();                    double radius = Convert.ToDouble(txtRadius.Text);            decimal checkX = (decimal)dt.Rows[0]["Latitude"];            decimal checkY = (decimal)dt.Rows[0]["Longitude"];                    // expect dt[0] to pass - as this is our check point            // We use for rather than fopreach because the later does not allow DELETE during loop execution            for(int index=0; index < dt.Rows.Count; index++)            {                DataRow dr = dt.Rows[index];                        decimal testX = (decimal)dr["Latitude"];                decimal testY = (decimal)dr["Longitude"];                        double testXzeroed = Convert.ToDouble(testX -= checkX);                double testYzeroed = Convert.ToDouble(testY -= checkY);                        double distance = Math.Sqrt((testXzeroed * testXzeroed) + (testYzeroed * testYzeroed));                        // mark for delete (not allowed in a foreach - so we use "for")                if (distance > radius)                    dr.Delete();            }                    // accept deletes            dt.AcceptChanges();                    GridView1.DataSource = dt.DefaultView;            GridView1.DataBind();        }

View 2 Replies View Related

Create Query To Average Data & Total/sum Data

Apr 21, 2008

Hello,
I am very new to SQL and just getting to learn this stuff. To make this question easier I will scale down the fields dramatically.

I have about 8000 records close to 2000 records for the last 4 years
and I would like to create a query that will create a table on my SQL server. I need to bind the data based on two items the Year and the Name and average several records. However, one record needs it's own calculation.

Here are my field names:
[year] ***4 choices 2007, 2006, 2005, 2004***
[name]
[rush_no] ***integer***
[rush_net] ***integer***
[YPC] *** This field needs to be calculated by [rush_net] divided by [rush_no]***decimal***

I also need to create the same table that will "total/sum" the same records.

View 7 Replies View Related

Fill Data Grid With Data From JOIN Query

Jul 8, 2013

I am working on a school project and have come up against a bit of a sticking point. I am supposed to be creating a very basic OMS, the teacher themselves have said they do not know how to do this (in previous years it has all be done via Access) but apparently I am a lucky one to be doing it in SQL this year.

So I have 2 tables for products in the system

products
+-----------+------------+
|productid |productname |
|Int |varchar(50) |
+-----------+------------+

productdetail
+---------+----------+------------+------+------+
|detailId |productid |description |price |stock |
|Int |Int |Text |Money |Int |
| |FK_From_ | | | |
| |productid_| | | |
| |products | | | |
+---------+----------+------------+------+------+

One of the user requirements of the OMS is to fill a data grid with product name and the product details which I have the query for or rather I have created a view for, which is then queried from a stored procedure.

CREATE VIEW [dbo].[v_stock]
AS SELECT tab_products.productname, tab_productdetails.description, tab_productdetails.image, tab_productdetails.price, tab_productdetails.stock
FROM tab_productdetails INNER JOIN
tab_products ON tab_productdetails.productid = tab_products.productid

The problem I am having is then returning the data from this query into a data grid, I think the reason is because when I attached the stored procedure to a table and then call that procedure via the table adapter there is a mismatch of the schema - specifically the table it is attached to does not contain the column "productName".

I am thinking I need to create a temporary table to fill the data grid with - however, I am not sure how I would create a temporary table.

Is there something I am missing or not done correctly. As far as I can tell the queries work as when I preview them they produce the expected results.

View 1 Replies View Related

Sum Old Data And New Data In Update Query

Jul 22, 2014

I have created a table in a database for a football that I want to update as the season progresses. Is there any way I can add the new data to the old data in my columns through SQL rather than searching for the old data, doing the maths in my head and doing a simple update query? I know it doesn't save much extra time but I can get awful lazy when it comes to extra maths!

Example would be:

Player Minutes
Adam 287

Adam has played 287 minutes prior to the most recent match in which he played 67 more. I would like to know if its possible to do an update where I can just simply add 67 onto the existing numbers with one query rather than find Adam's minutes, use a calculator, do a table update.

View 4 Replies View Related

If Else Query For A Complex Data Set

Jan 4, 2007

I am creating an application which uses logic similar to J.D.Edwards (for those of you are familiar with its wildcarding data structure). 
 
Basically, a customer purchases a particular house, with a particular elevation, in a particular community.  This data is stored in a Customer table. From the customer’s selection (community, plan, elevation) criteria, I need to create a unique list of options from data stored in an optionmaster table.
 
A customer’s data looks similar to this in the customer table:
 





CustomerID

CommunityID

Community Name

PlanID

Plan Name

ElevationID

ElevationName


1234567

7

Hickory Hills

25

Allen

3

C
 
The Optionmaster table is structured like this (there are actually about 1000 records):
 





Option #

Option Name

CommID

Community Name

PlanID

Plan Name

ElevID

Elevation Name

Price


4567

Optional Window

0

+

0

+

0

+

250


1234

Optional Door

0

+

0

+

0

+

100


1234

Optional Door

7

Hickory Hills

0

+

0

+

0


4567

Optional Brick

0

+

25

Allen

0

+

250


9101

Optional Dormer

0

+

25

Allen

2

B

50


9125

Optional Tub

8

Smithville

0

+

0

+

800


9125

Optional Kitchen

0

+

0

Lori

0

+

2500
 
 
 





First. Based on the customer’s table I need to first select all options = to their community, as well as those available to communities everywhere (+).  In some cases the same option is maintained for both at both levels.  In that case the community specific option must be selected. 
 
To do this I think I need an if else statement to select those records:
 
In this case, if CommID =7, select record, else select 0.  This eliminates the other Smithville community and pulls the correct option # 1234.
 
The result would look like this:


 

 

 

 

 

 

 

 

 


Option #

Option Name

CommID

Community Name

PlanID

Plan Name

ElevID

Elevation Name

Price


4567

Optional Window

0

+

0

+

0

+

250


1234

Optional Door

7

Hickory Hills

0

+

0

+

0


4567

Optional Brick

0

+

25

Allen

0

+

250


9101

Optinal Dormer

0

+

25

Allen

2

B

50


9125

Optinal Kitchen

0

+

0

Lori

0

+

2500


 

 

 

 

 

 

 

 

 


Second, from this dataset, I need to select all options equal to the plan ID, and those which apply to all plans (+).  So, the Lori Plan data goes away.
 
Something like,  If the plan ID = 25, select record, else 0.  the result would be:


 

 

 

 

 

 

 

 

 


Option #

Option Name

CommID

Community Name

PlanID

Plan Name

ElevID

Elevation Name

Price


4567

Optional Window

0

+

0

+

0

+

250


1234

Optional Door

7

Hickory Hills

0

+

0

+

0


4567

Optional Brick

0

+

25

Allen

0

+

250


9101

Optinal Dormer

0

+

25

Allen

2

B

50


 

 

 

 

 

 

 

 

 


Third and finally, based on that dataset, I would have to select any elevation specific options for that plan or options for all elevations of that  plan (+). 
 
Something like this: If the Elevation ID = 2, select record, else. 0.  Note the elevation B data goes away.
 
The final result would be for this customer is:


 

 

 

 

 

 

 

 

 


Option #

Option Name

CommID

Community Name

PlanID

Plan Name

ElevID

Elevation Name

Price


4567

Optional Window

0

+

0

+

0

+

250


1234

Optional Door

7

Hickory Hills

0

+

0

+

0


4567

Optional Brick

0

+

25

Allen

0

+

250
 
Any assistance anyone can provide in coming up with a sql statement to do this would be appreciated.
 
 

View 5 Replies View Related

Query Not Returning Data!

Oct 21, 2007

Hi! I have a sql query in stored procedure: SELECT     Salutation + ' ' + FirstName + ' ' + LastName AS fullname
Ok, this returns a value if salutation is not null, but if the salutation is null it doesn't return any value, I was thinking if the saluation is null then I would atleast get the firstname and last name. Any help appreciated on this.

View 4 Replies View Related

Query Help, Massaging The Data

Nov 14, 2007

I need to combine the data into ONE Row. Any Ideas ?
here is what the Data looks like now


FirstQuery


WorkOrder
CID
Address1
Address2
Open24
NicePeople
NicePlace


33333
6666


Yes



33333
6666
Green Street





67666
7777




No

67666
7777


No



67666
7777
Mad Ave





I need it to look like this


FirstQuery


WorkOrder
CID
Address1
Address2
Open24
NicePeople
NicePlace


33333
6666
Green Street

Yes



67666
7777
Mad Ave

No

No

 
Here is my Query
SELECT RouteCustomer.WorkOrder, RouteCustomer.CID, IIf([ServiceHistorydetails].[FieldName]="Address1",[ServiceHistoryDetails].[ToValue],"") AS Address1, IIf([ServiceHistorydetails].[FieldName]="Address2",[ServiceHistoryDetails].[ToValue],"") AS Address2, IIf([ServiceHistorydetails].[FieldName]="Open24",[ServiceHistoryDetails].[ToValue],"") AS Open24, IIf([ServiceHistorydetails].[FieldName]="NicePeople",[ServiceHistoryDetails].[ToValue],"") AS NicePeople, IIf([ServiceHistorydetails].[FieldName]="NicePlace",[ServiceHistoryDetails].[ToValue],"") AS NicePlaceFROM RouteCustomer RIGHT JOIN ServiceHistoryDetails ON RouteCustomer.WorkOrder = ServiceHistoryDetails.WorkOrderGROUP BY RouteCustomer.WorkOrder, RouteCustomer.CID, IIf([ServiceHistorydetails].[FieldName]="Address1",[ServiceHistoryDetails].[ToValue],""), IIf([ServiceHistorydetails].[FieldName]="Address2",[ServiceHistoryDetails].[ToValue],""), IIf([ServiceHistorydetails].[FieldName]="Open24",[ServiceHistoryDetails].[ToValue],""), IIf([ServiceHistorydetails].[FieldName]="NicePeople",[ServiceHistoryDetails].[ToValue],""), IIf([ServiceHistorydetails].[FieldName]="NicePlace",[ServiceHistoryDetails].[ToValue],"");
If anyone has any ideas how I can Parse this data correctly please help me out.
Thank you
 

View 2 Replies View Related

How To Sort Data Using SQL Query

Dec 18, 2007

Dear All,

i need your help,

i had created a table student, studentid column with alpha numeric primary key with varchar datatype

now my problem: i want to sort the student id accroding to studentid like

STU1
STU2
STU3
STU4
STU5
.
.
.
STU9
STU10
STU11

but i’m getting the sorted result like this, how to overcome this problem,guide me PLEASE

STU1
STU10
STU11
STU12
.
.
.

STU100
.
.
.

STU1000
STU10000
STU2
STU20
STU200
STU2000
STU20000
STU20001


Thank's In Advances

View 9 Replies View Related

Sql Query To Loop Over Data From Xml, Help!

Apr 7, 2008

 Hi All. How do i loop over to extract data out of a xml parameter in order to insert that into a table along with other input. For example if the xml is <Id>1</Id> <Id>2</Id> <Id>3</Id> I want to input values into table (1,data2,data3) and (2,data2,data3) and (3,data2,data3). How do i do that? 

View 6 Replies View Related

How To Distinct Data By Using MS SQL Query

Apr 29, 2008

Select A.SNO , A.Name , B.Picfrom Student A Left Join Picture BWhere A.SNo = B.PNoNo     SNo            Name                Pic1      000            Andy                /Doc/andy.jpg2      001            Andy                /Doc/andy2.jpg3      002            VIVI                /Doc/vivi.jpg4      003            VIVI                /Doc/Vivi2.jpg The same person will only show 1 pic Pathlike this resultNo     SNo            Name                Pic1      000            Andy                /Doc/andy.jpg3      002            VIVI                /Doc/vivi.jpgcan you please help? I trid use Group By but it not works..thank you

View 10 Replies View Related

Query With 2 Sets Of Data

May 7, 2008

I am trying to query one table and get two different timeperiods of data, I am summing monthly totals to provide a running year total, but I also need last month's total in a seperate column. This is what I have so far but the subquery makes me group it which provides duplicate grouping.DECLARE @LASTPD AS INT
SET @LASTPD = (SELECT MAX(LASTPERIOD) FROM TABLE)
SELECT NAME,
POST_PD AS [MONTH],SUM(CHARGE_AMOUNT) AS MONTHLY_$,
LASTMONTH.LAST_MONTH,(SELECT SUM(CHARGE_AMOUNT) AS LAST_MONTH
FROM TABLE INNER JOIN TABLE2
ON TABLE2.NAME = TABLE.NAME
WHERE POST_PD = @LASTPD
AND TABLE2.NUM= 539
GROUP BY NAME) AS LASTMONTH
INTO #TEMP_SAFROM TABLE
INNER JOIN TABLE2
ON TABLE2.NAME = TABLE.NAME,(SELECT SUM(CHARGE_AMOUNT) AS LAST_MONTH
FROM TABLEWHERE TABLE2.NUM = 539
GROUP BY NAME, POST_PDORDER BY NAME, POST_PD
SELECT NAME,
             LAST_MONTH,
CAST(SUM(MONTHLY_$)AS DECIMAL(20,2)) AS YEARLY_$
FROM #TEMP_SA
GROUP BY NAME
ORDER BY NAME

View 13 Replies View Related

SQL Query For Data Between 2 Dates

May 17, 2005

Hi.,
 Can anyone please assist me in getting the following SQL Query to work. It returns no errors but also returns no records even though there is actually data in my database for that period.
Dim DCriteria as StringDCriteria = "StartDate <= " & EDateDCriteria = DCriteria & " AND EndDate >= " & SDatestrSQL = "SELECT * FROM vwLeavePlan WHERE " & DCriteria
This results in the follwoing SQL Statement:
strSQL = SELECT * FROM vwLeavePlan WHERE StartDate <= 31/05/2005 AND EndDate >= 01/05/2005
Regards.
Peter

View 14 Replies View Related

Query To Get The Data Of Three Tables?

Aug 11, 2005

Hi:

I have three tables in my db. One is clients, other calls, and other visits.
I want to get all the calls and visits of all clients in my db every row in each table separate in one row in the results table.
How can I do it?

View 3 Replies View Related

Query Table Without Data

Mar 13, 2006

I'm writting a stored proc that has to query 2 tables. One table is a table of "jobs" and the other table contains jobs that have been invoiced (2 tables are jobs and invoicedJobs). The invoiced table only contains records for jobs that have an invoice and not jobs that do not have an invoice.
My dilemma is that I need to write a query that can retrieve all un-invoiced jobs in my stored proc. You can't rightly join a table that does not have a relationship with another table (can you?). So in my query for jobs with an invoice, I simply join my jobs table and invoice table based on a job id that both tables contain. But how could I perform a query for jobs that do not exist in my invoice table inside my stored proc? Any help would be greatly appreciated.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved