this is the query im trying to execute in sql server.please let me know what is the error in this
SELECT "PROJECT"."PROJ_NAM", ' ' as dev_name, "PROJECT_FUND"."F_FUND_ID" as fund_id, view_on_watch_list.on_date
FROM LEFT OUTER JOIN view_on_watch_list ON project.proj_id =view_on_watch_list.proj_id , "PROJECT_FUND" LEFT OUTER JOIN "FUND" ON "PROJECT_FUND"."F_FUND_ID" = "FUND"."FUND_ID" AND project.proj_id = project_fund.f_proj_id , "PROJECT" WHERE (("PROJECT"."PROJ_ID" = 1))
select "PROJECT"."PROJ_ID", ' ' AS DEV_TYPE from PROJECTFROM LEFT OUTER JOIN
Enter Table_Name after "FROM" clause...
project.proj_id = project_fund.f_proj_id , "PROJECT" WHERE (("PROJECT"."PROJ_ID" = @.proj_id))
select "PROJECT"."PROJ_ID", ' ' AS DEV_TYPE from PROJECT
I didn't get what you want to do... Post your table structure, data & your requirement.|||actually im a beginner in MSSQL.im not aware of this LEFT OUTER JOIN syntax.
i tried with placing table name after 'LEFT' ,below error was thrown
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Tables or functions 'project' and 'PROJECT' have the same exposed names. Use correlation names to distinguish them.|||Wel Come :)
Before you use query in application code, run & check it using SQL Query Analyzer.
Develop query step by step i.e. don't write entire query at once but create 1st then 2nd phrase etc...
Spend some time to learn, you can refer SELECT syntax in Books OnLine from SQL Query Analyzer.|||Hi
If you are just starting you might find this a gentler learning curve:
http://www.w3schools.com/sql/sql_intro.asp
rajeshpatel is spot on - don't write out loads at once - write a small section, run, if it works write some more else refer to the link and correct.
HTH|||thank u rajesh.im familiar with sql's(DDLS and DMLS).please guide me to the correct query for the above one.|||I'm afraid the SQL is so bad it is not possible to tell what you want you want to do. I strongly recommend you read the link and have another stab at writing it. As you come up against problems get back to us with specifics.
If you build up a bit at a time it might be possible to infer what you are actually attempting to do.
Showing posts with label thisselect. Show all posts
Showing posts with label thisselect. Show all posts
Monday, March 26, 2012
Monday, March 12, 2012
Inconsistent query result
Hi, I have one view and three tables. My query is like this
select * from VW_I_FACT_SERVICE
inner join DIM_CUSTOMER
on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
inner join DIM_PERIOD
on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
inner join DIM_AREA
on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
It wil return only 6 records.
If I do this
select * from VW_I_FACT_SERVICE
inner join DIM_CUSTOMER
on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
or this
select * from VW_I_FACT_SERVICE
inner join DIM_PERIOD
on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
or this
select * from VW_I_FACT_SERVICE
inner join DIM_AREA
on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
They will return 248407 records for each query.
----
And If I do this
select top 100000 * from VW_I_FACT_SERVICE
inner join DIM_CUSTOMER
on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
inner join DIM_PERIOD
on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
inner join DIM_AREA
on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
It will return exactly 100000 records.
----
I really do not have any idea why my first query only returns 6 records?
I'm using a Pentium 4 2.8GHz PC with 1GB of RAM. Windows 2000 Advanced
Server SP4, SQL Server 2000 Enterprise Edition SP3a.
Thank You in Advance...
Regards,
Jono Indrawijaya
PT eBiz Cipta Solusi - Indonesia
Microsoft Certified PartnerJono,
Certainly adding TOP 100000 should not increase the size of
the result set from 6 to 100000. First, can you run
SELECT @.@.version
to identify which build of SQL Server you are using? Also, could you
post the CREATE TABLE and CREATE VIEW statements for these
tables and view?
Steve Kass
Drew University
Jono Indrawijaya wrote:
>Hi, I have one view and three tables. My query is like this
>select * from VW_I_FACT_SERVICE
>inner join DIM_CUSTOMER
>on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
>inner join DIM_PERIOD
>on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
>inner join DIM_AREA
>on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
>It wil return only 6 records.
>--
>If I do this
>select * from VW_I_FACT_SERVICE
>inner join DIM_CUSTOMER
>on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
>or this
>select * from VW_I_FACT_SERVICE
>inner join DIM_PERIOD
>on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
>or this
>select * from VW_I_FACT_SERVICE
>inner join DIM_AREA
>on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
>
>They will return 248407 records for each query.
>----
>And If I do this
>select top 100000 * from VW_I_FACT_SERVICE
>inner join DIM_CUSTOMER
>on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
>inner join DIM_PERIOD
>on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
>inner join DIM_AREA
>on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
>It will return exactly 100000 records.
>----
>I really do not have any idea why my first query only returns 6 records?
>I'm using a Pentium 4 2.8GHz PC with 1GB of RAM. Windows 2000 Advanced
>Server SP4, SQL Server 2000 Enterprise Edition SP3a.
>Thank You in Advance...
>
>|||Dear Steve,
I found that the Customer_ID field in FACT_CSUTOMER is bigint, but in the
I_FACT_SERVICE is int. Now it is returning correct recordset after I change
those data type. Thx for u're response, it leads me to this finding.. =)
Regards,
Jono
"Steve Kass" wrote:
> Jono,
> Certainly adding TOP 100000 should not increase the size of
> the result set from 6 to 100000. First, can you run
> SELECT @.@.version
> to identify which build of SQL Server you are using? Also, could you
> post the CREATE TABLE and CREATE VIEW statements for these
> tables and view?
> Steve Kass
> Drew University
> Jono Indrawijaya wrote:
>
>
select * from VW_I_FACT_SERVICE
inner join DIM_CUSTOMER
on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
inner join DIM_PERIOD
on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
inner join DIM_AREA
on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
It wil return only 6 records.
If I do this
select * from VW_I_FACT_SERVICE
inner join DIM_CUSTOMER
on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
or this
select * from VW_I_FACT_SERVICE
inner join DIM_PERIOD
on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
or this
select * from VW_I_FACT_SERVICE
inner join DIM_AREA
on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
They will return 248407 records for each query.
----
And If I do this
select top 100000 * from VW_I_FACT_SERVICE
inner join DIM_CUSTOMER
on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
inner join DIM_PERIOD
on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
inner join DIM_AREA
on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
It will return exactly 100000 records.
----
I really do not have any idea why my first query only returns 6 records?
I'm using a Pentium 4 2.8GHz PC with 1GB of RAM. Windows 2000 Advanced
Server SP4, SQL Server 2000 Enterprise Edition SP3a.
Thank You in Advance...
Regards,
Jono Indrawijaya
PT eBiz Cipta Solusi - Indonesia
Microsoft Certified PartnerJono,
Certainly adding TOP 100000 should not increase the size of
the result set from 6 to 100000. First, can you run
SELECT @.@.version
to identify which build of SQL Server you are using? Also, could you
post the CREATE TABLE and CREATE VIEW statements for these
tables and view?
Steve Kass
Drew University
Jono Indrawijaya wrote:
>Hi, I have one view and three tables. My query is like this
>select * from VW_I_FACT_SERVICE
>inner join DIM_CUSTOMER
>on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
>inner join DIM_PERIOD
>on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
>inner join DIM_AREA
>on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
>It wil return only 6 records.
>--
>If I do this
>select * from VW_I_FACT_SERVICE
>inner join DIM_CUSTOMER
>on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
>or this
>select * from VW_I_FACT_SERVICE
>inner join DIM_PERIOD
>on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
>or this
>select * from VW_I_FACT_SERVICE
>inner join DIM_AREA
>on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
>
>They will return 248407 records for each query.
>----
>And If I do this
>select top 100000 * from VW_I_FACT_SERVICE
>inner join DIM_CUSTOMER
>on VW_I_FACT_SERVICE.Customer_ID = DIM_CUSTOMER.Customer_ID
>inner join DIM_PERIOD
>on VW_I_FACT_SERVICE.Time_Period_ID = DIM_PERIOD.Time_ID
>inner join DIM_AREA
>on VW_I_FACT_SERVICE.Area_ID = DIM_AREA.Area_ID
>It will return exactly 100000 records.
>----
>I really do not have any idea why my first query only returns 6 records?
>I'm using a Pentium 4 2.8GHz PC with 1GB of RAM. Windows 2000 Advanced
>Server SP4, SQL Server 2000 Enterprise Edition SP3a.
>Thank You in Advance...
>
>|||Dear Steve,
I found that the Customer_ID field in FACT_CSUTOMER is bigint, but in the
I_FACT_SERVICE is int. Now it is returning correct recordset after I change
those data type. Thx for u're response, it leads me to this finding.. =)
Regards,
Jono
"Steve Kass" wrote:
> Jono,
> Certainly adding TOP 100000 should not increase the size of
> the result set from 6 to 100000. First, can you run
> SELECT @.@.version
> to identify which build of SQL Server you are using? Also, could you
> post the CREATE TABLE and CREATE VIEW statements for these
> tables and view?
> Steve Kass
> Drew University
> Jono Indrawijaya wrote:
>
>
Labels:
customer_id,
database,
dim_customeron,
inconsistent,
microsoft,
mysql,
oracle,
query,
server,
sql,
tables,
thisselect,
view,
vw_i_fact_service,
vw_i_fact_serviceinner
Friday, February 24, 2012
Include "/" in select statement
I wanted to create something like this:
Select (FirstItem + "/" + SecondItem) AS Item
Select (FirstItem + "/" + SecondItem) AS Item
but I get error. Is there anything wrong with this code?
P.S. I'm using mssql 2000
Hi,
in case FirstItem and SecondItem field are varchar type themselves, just replace double quotes ("/") with single quotes ('/')
e.g Select (FirstItem +'/' + SecondItem) AS Item
|||
Adding tojoteke's solution, if the columns are not of same datatype, you would do a CONVERT.
SELECT CONVERT(varchar(50),FirstItem ) +'/' + CONVERT(varchar(50),secondItem) AS Item
Subscribe to:
Posts (Atom)