select PaySlipDate,EmpID, case ADCode when 'GPF' then ADAmount else 0 end GPF, case ADCode when 'GPF.ADV' then ADAmount else 0 end 'GPF.ADV' from EmpSalaryRecord
It is showing multiple records of each employee for each date. First a record with GPF and GPF.ADV both zero and then records with values. I want a single record for each date and employee.
We have a sort of complex user structure in the sense that depending on the type of user the data resides in different tables. Therefor I needed a stored procedure that finds out what table to look for a certain column in. Below is such a stored procedure and it works like it should but my problem is that I don't know how to retrieve the result (which should be a string so can't use RETURN).
I've tried using an OUTPUT variable but since I just run EXEC (@statement) in the end I can't really set an output variable the common way (as in EXEC @outputVariable = PMC_User_GetUserValue(arg1, arg2..)) or can I?
I have also tried to use SELECT to catch the result somehow but no luck and Google didn't help either so now I'm hoping for one of you... Notice that you don't have to bother about much of the code except for the end of it where I want it to return somehow or figure out a way to call this stored procedure and retrieve the result.
Thanks in advance ripern
-- Retrieves the value of column @columnName for credential id @credID ALTER PROCEDURE [dbo].[PMC_User_GetUserValue] @credID int, @columnName nvarchar(50) AS
DECLARE @userDataTable nvarchar(50) DECLARE @userDataID int DECLARE @statement nvarchar(500) SET @statement = ' '
SET @userDataID = (SELECT PMC_UserMapping.fk_userDataID FROM PMC_UserMapping INNER JOIN PMC_User ON PMC_UserMapping.fk_user_id = PMC_User.id WHERE PMC_User.fk_credentials_id = @credID)
SET @userDataTable = (SELECT PMC_UserType.userDataTable FROM PMC_UserType INNER JOIN PMC_UserMapping ON PMC_UserType.id = PMC_UserMapping.fk_usertype_id INNER JOIN PMC_User ON PMC_UserMapping.fk_user_id = PMC_User.id WHERE PMC_User.fk_credentials_id = @credID)
SET @statement = 'SELECT ' + @columnName + ' AS columnValue FROM ' + @userDataTable + ' WHERE id=' + convert(nvarchar, @userDataID)
-- Checks whether the given column name exists in the user data table for the given credential id. IF EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=@userDataTable AND COLUMN_NAME=@columnName ) BEGIN EXEC (@statement) END
let's say I have a table named "myTable" in a SQL database:
UniqueID FirstName FamilyName
1 Elizabeth Moore
2 Chris Lee
2 Robert McDonald's
I want to create a SQL query should contain a parameter for example: SELECT * FROM myTable WHERE UniqueID = @TextBox OR FirstName = @TextBox OR FamilyName = @TextBox,
and when I type in my TextBox the ' * ' character, it should retrieve the whole table...
hope anybody understood, will be happy to explain more.
hi, i am a nubie, and struggling with the where clause in my stored procedure. here is what i need to do: i have a gridview that displays records of monthly view of data. i want the user to be able to page through any selected month to view its corresponding data. the way i wanted to do this was to set up three link buttons above my gridview: [<<Prev] [Selected Month] [Next>>] the text for 'selected month' would change to correspond to which month of data was currently being displayed in the gridview (and default to the current month when the application first loads). i am having trouble writing the 'where' clause in my stored procedure to retrieve the selected month and year. i am using sql server 2000. i read this article (http://forums.asp.net/thread/1538777.aspx), but was not able to adapt it to what i am doing. i am open to other suggestions of how to do this if you know of a cleaner or more efficient way. thanks!
Is it possible to retrieve a particular row from a result set? For eg if my query returns 5 rows and i want to just retrieve the 3rd row from the result....is it possible? If yes...can someone tell me the syntax for it....would appreciate the gr8 help...
Hi I'am practically new in C#, so I want to ask you guys some question.Let say I have this query:"Select EmployeeID, EmpName from PI_Employee"How can I retrieve the result from EmployeeID column and EmpName column and put it into collections of array, so I can call the array and use it again in another function. Can I possibly do that in C# ? if so, how ? please help me guys, I'm on the edge of nervous wreck in here so I could use a little help, any kinds of help. Thanks. Best Regards.
I have two tables that have no relation. However, both have a column which has a field of nvarchar(50) that I want to retrieve together in one operation and bind to a DropDownList in a sorted fashion. So, what I'm trying to achieve is this: 1. SELECT name FROM table1 2. SELECT name FROM table2 3. Join the two results together and order them alphabetically 4. Return the result set I'm not sure how to do this or even if it's possible. Ideally I'm hoping it can be done in a stored proc.
Is there anyone who was able to successfully retrieve a full result set? I'm really having troubles getting the result after executing my query. Its really even hard to get sample codes over the net.
Goal: My request is the retrieve the return result from sp_Test as 8, 2, 4, 1 ,3 (take a look at picture 1) based on the chronological list from User-Defined Table Type dbo.tvf_id.
Problem: When I execute the stored procedure I sp_Test I retrive the list that is from 1 to 8. I don't know how to do it?
Information: I'm using SQL server 2012
create table datatable (id int, name varchar(100), email varchar(10), phone varchar(10), cellphone varchar(10), none varchar(10) ); insert into datatable values
HI, I ran a select * from customers where state ='va', this is the result...
(29 row(s) affected) The following file has been saved successfully: C:outputcustomers.rpt 10826 bytes
I choose Query select to a file then when I tried to open the customer.rpt from the c drive I got this error message. I am not sure why this happend invalid TLV record
As the topic suggests I need the end results to show a list of shows and their dates ordered by date DESC. Tables I have are structured as follows:
SHOWS showID showTitle
SHOWACCESS showID remoteID
VIDEOS videoDate showID
SQL is as follows:
SELECT shows.showID AS showID, shows.showTitle AS showTitle, (SELECT MAX(videos.videoFilmDate) AS vidDate FROM videos WHERE videos.showID = shows.showID) FROM shows, showAccess WHERE shows.showID = showAccess.showID AND showAccess.remoteID=21 ORDER BY vidDate DESC;
I had it ordering by showTitle and it worked fine, but I need it to order by vidDate. Can anyone shed some light on where I am going wrong?
In the Control flow tab, I have an Execute SQL Task that outputs full Result set into a variable of an object type. Now how can I write the contents of the Full Result Set into a text file using Script Task. I also want to format the following way while I output into a file:
Column Name 1 : Column Value
Column Name 2: Column Value and so on
I tried writing the contents of the Object Variable into a file, but the file had an output of single word: System.__ComObject.
Code for Writing the Full Result Set into a Text File
Dim RSsqloutput as String = Dts.Variables("objVariable").Value.ToString
Dim strVal as String = "File completed on " & Now() & vbCrLf & "------------------------------------------------------" & vbCrLf
Hello, I have two tables: Customer Training Requests has say two columns.Customer - Class Requested a 1b 1c 1a 2b 2c 3a 3 I have another table called packages, which has packages of class.Package No. Class1 11 2 I want to write a query which will return only those customers who have requested exactly the classes in a particular package.so in above example if the package is 1 the query should return only customer b as only customer b has requested class 1 and 2. Any suggestions? Thanks,Paresh.
Hello, how can do the following using sql: if exists(select * from siteindex where site_url like '%msn.com')ThenUpdate siteindex Set dmodified = GetDate(), isFullPage = 0, fp_flname = 'filename', fp_iWidth = 800, fp_iheight = 600 Where site_url = '%msn.com' else insert into siteindex (site_url, dcreated, dmodified, isFullPage, fp_flname, fp_iWidth, fp_iHeight) Values ('msn.com', GetDate(), GetDate(), 0, 'filename', 800, 600) I cant get the syntax right. Thanks!
Hi all, I have a problem with retrieving data from lookup tables. Ok here is the issue I have a Tables ... Tables | Schools StuAccount Fields | Sch_Id (pk) Student_ID (pk) School_Name AccountableSch_Id DistrictName TestedSch_Id ParticipatedSch_Id Ok, so i have two tables Schools and StuAccount, each has one primary key and and the StuAccount has three foreign keys that associates to the Schools TABLE which has a the definition of school names wich i want to retrieve for all three foreign key in the stuaccount table. Here is what i want .... Student_ID AccountableSch_Id Shool_Name( this the name of the AccountableSch_Id ) TestedSch_Id Shool_Name( this the name of the TestedSch_Id) ParticipatedSch_Id Shool_Name( this the name of the ParticipatedSch_Id) I just want to look up the id and put the school name in the final resulting join and i have no idea how to lookup the table School three time and put school name for all three foreign keys.?? Any help will be much appreciated. Thanks
please help me write a query: I have a user function dbo.udf_Valid which is return true or false (@SID ,@PType,@Group,@Date)
Table 1 with this info: SID PType Group 12 12 123 45 1 456
Table2 with this info: PType PType2 12 13 12 45 12 8 1 8 1 9
when I pass the data from table1 to the function I am Okay. The complexity starts when table2 is involved. I need to pass PType2 to the function if Ptype is exists in table1. If function returns true for one of the PType2 return true in all other cases false.
I need to be able to filter out duplicates that have different values in a particular field.
For example, I have a table that contains the following:
Code:
WBS1 WBS2 WBS3 Amount Section 123 13 00 475 F 123 13 00 0 L 123 21 01 125 C 123 24 03 50 L
I need to filter out the first two lines because they have the same values for the first three columns but the last column under 'Section' has different values.
Hello I'm new on sql server and I wonder if there's an specific order for writing a query's clauses (joins, and other conditions in where clause or even the order of the tables in the from clause), I mean, I have a query that takes 1 minute executing, but if I execute the same query after moving the tables in the from clause (changing the order) It takes 5 seconds, could you please tell me Why ??? and what's the best order from writing a query ?
This is the query I was talking about:
SELECT TREP_VALOR_PRECIOS.CDPRECIO, TREP_VALOR_PRECIOS.NMANO, TREP_VALOR_PRECIOS.NMSEMANA, ISNULL(DBO.FNCREP_VALORPRECIO(TREP_PRECIOS.CDPRECI O,0,TREP_VALOR_PRECIOS.NMSEMANA,TREP_VALOR_PRECIOS .NMANO),0) VRPAGO_COBRO, UN_TASASCAMBI.TASTASACAMB VRTASA_CAMBIO, TREP_PRECIOS.CDTIPO_PRECIO, TREP_VALOR_PRECIOS.SNACTIVO, 'N' SNACTIVAR FROM UN_TASASCAMBI, -- I just moved this one to the end of the from clause T2_CALENDARIO, -- I just moved this one to the end of the from clause UN_MONEDEXTRA, TREP_PRECIOS TREP_PRECIOS_BASE, TREP_VALOR_PRECIOS, TREP_PRECIOS WHERE T2_CALENDARIO.CALFECHAINICIAL BETWEEN UN_TASASCAMBI.TASFECHDESD AND UN_TASASCAMBI.TASFECHHAST AND UN_TASASCAMBI.TASCOMPANIA = UN_MONEDEXTRA.MEXCOMPANIA AND UN_TASASCAMBI.TASMONECAMB = UN_MONEDEXTRA.MEXCODIGO AND T2_CALENDARIO.CALSEMANA = TREP_VALOR_PRECIOS.NMSEMANA AND T2_CALENDARIO.CALANO = TREP_VALOR_PRECIOS.NMANO AND T2_CALENDARIO.CALTIPOFRUTA = '01' AND UN_MONEDEXTRA.MEXCOMPANIA = TREP_PRECIOS_BASE.CDCOMPANIA AND UN_MONEDEXTRA.MEXCODIGO = TREP_PRECIOS_BASE.CDMONEDA AND TREP_PRECIOS_BASE.CDMONEDA <> 'PESOC' AND TREP_PRECIOS_BASE.CDPRECIO = TREP_VALOR_PRECIOS.CDPRECIO AND TREP_VALOR_PRECIOS.SNACTIVO = 'S' AND TREP_VALOR_PRECIOS.CDPRECIO = DBO.FNCREP_OBTENER_PRECIO_BASE(TREP_PRECIOS.CDPREC IO) AND TREP_PRECIOS.CDTIPO_PRECIO = 'F'
Now, I want search for records with employee id 1 in a way that if column emp1 contains 1 then I want the data in column emp2, and if column emp2 contains 1, then I want data in column emp1.
The output has to be a single column with no duplicate values. In the above example, for employee id 1, the output would be, 2,5 and 6 only.
This table has lakhs of records. I have to scan both columns for a given employee id. What will be the most optimized way to retrieve the data faster. Also, do I need to restructure this table for faster data retrieval? I have indexes on emp1 and emp2 columns. Do we need union here and if yes, what is the best optimized query for the same?
Mine Below Query is taking too much execution time. I am using this query in one of my sp. Is there any other way to write this query?
Declare @p_Location_Code nvarchar(10) Declare @p_ShowNearFarRate int DECLARE @p_Data_Show_Flag int
Set @p_ShowNearFarRate = 1 Set @p_Data_Show_Flag = 1
select X.Main_Party_Role , X.SET_ID, X.TradeVisionId, X.EntityId, DBO.GET_ENTITY_TICKER (X.EntityId) Ticker, X.Done, X.MatchDate, X.Main_Party_Id, X.BUYER_MNEMONIC, X.SELLER_MNEMONIC, X.Other_Party_Id, DBO.GET_DDMONYYYY_DATE_FORMAT(X.Main_Near_Dt) Main_Near_Dt, DBO.GET_DDMONYYYY_DATE_FORMAT(X.Main_Far_Dt) Main_Far_Dt, X.Amounts, 'Amount' = Case When ((ISNULL(X.Amount,0) >20) ) then Case When @p_Location_Code = 'NY44' then '20+' Else convert(nvarchar,x.Amount) End Else convert(nvarchar,x.Amount) End, X.Price, X.Duration, X.Other_Party_Bro, X.Main_Party_Bro, X.Main_Party_State, X.Other_Party_State, 'Main_Party_Near_Parse' = Case When (X.Main_Party_State=184 and X.Other_Party_State=184) THEN X.Main_Party_Near_Parse Else Case When @p_ShowNearFarRate = 1 then X.Main_Party_Near_Parse End End, 'Main_Party_Far_Parse' = Case When (X.Main_Party_State=184 and X.Other_Party_State=184) THEN X.Main_Party_Far_Parse Else Case When @p_ShowNearFarRate = 1 then X.Main_Party_Far_Parse End End, X.Main_Party_Spread BPS, 'Main_Party_Amt' = Case When @p_Location_Code <> 'NY44' then X.Main_Party_Amt Else Case When (ISNULL(X.DONE,0) = 1 or X.Main_Party_State = 184 or X.Main_Party_State = 106) then X.Main_Party_Amt Else Case When ISNULL(X.Main_Party_Amt,0) <= 20 then X.Main_Party_Amt Else 20 End End End, X.Other_Party_Near_Parse, X.Other_Party_Far_Parse, X.Other_Party_Spread, X.Other_Party_Amt, X.LOCATION_CODE, X.Color_Value Org_Color_Value, 'Color_Value' = Case When @p_Location_Code = 'NY44' then Case When X.Color_Value=500 then 500 + X.CallMe_Btn_Value Else Case When X.Color_Value>= 284 and Isnull(x.done,0) <> 1 then 284 + X.CallMe_Btn_Value Else Case When X.Color_Value=201 then 0 + X.CallMe_Btn_Value Else Case When X.Color_Value=200 then 0 + X.CallMe_Btn_Value Else Case When X.Color_Value=184 then 0 + X.CallMe_Btn_Value Else Case When X.Color_Value=106 then 16 + X.CallMe_Btn_Value Else Case When X.Color_Value=101 then 0 + X.CallMe_Btn_Value Else Case When X.Color_Value=100 then 0 + X.CallMe_Btn_Value Else Case When X.Color_Value=16 then 16 + X.CallMe_Btn_Value Else 0 + X.CallMe_Btn_Value End End End End End End End End End Else Case When X.Color_Value>=300 then 300 + X.CallMe_Btn_Value Else Case When X.Color_Value=284 then 284 + X.CallMe_Btn_Value Else Case When X.Color_Value=201 then 201 + X.CallMe_Btn_Value Else Case When X.Color_Value=200 then 200 + X.CallMe_Btn_Value Else Case When X.Color_Value=184 then 184 + X.CallMe_Btn_Value Else Case When X.Color_Value=106 then 106 + X.CallMe_Btn_Value Else Case When X.Color_Value=101 then 101 + X.CallMe_Btn_Value Else Case When X.Color_Value=100 then 100 + X.CallMe_Btn_Value Else Case When X.Color_Value=16 then 16 + X.CallMe_Btn_Value Else 0 + X.CallMe_Btn_Value End End End End End End End End End End, X.Main_Party_Strike_State, X.Other_Party_Strike_State, 'BACK_COLOR' = (DBO.Fn_Get_TradeVisionRR_Back_Color_Value (@p_Location_Code, X.Color_Value)) , 'FORE_COLOR' = (DBO.Fn_Get_TradeVisionRR_Fore_Color_Value (@p_Location_Code, X.Color_Value)) FROM ( SELECT Y.TradeVisionFileIdSET_ID, 'BUYER'Main_Party_Role, Y.TradeVisionId, Y.EntityId, Y.Done, Y.MatchDate, Y.BuyerIdMain_Party_Id, DBO.GET_CUSTOMER_MNEMONIC(Y.BUYERId) BUYER_MNEMONIC, 'SELLER_MNEMONIC' = Case When Y.Done = 1 THEN DBO.GET_CUSTOMER_MNEMONIC(Y.SELLERID) Else Case When ( @p_Location_Code <> 'NY44' AND Y.BuyerState = 184AND Y.BuyerState = 184AND Y.IsBNearPraceTouched = 1 AND Y.IsSNearPraceTouched = 1 AND Y.IsBFarPraceTouched = 1AND Y.IsSFarPraceTouched = 1 AND Y.IsBSpreadTouched = 1 AND Y.IsSSpreadTouched = 1 AND Y.IsBAmtTouched = 1 AND Y.IsSAmtTouched= 1 AND Y.BuyerNearPrace = Y.SellerNearPrace AND Y.BuyerFarPrace = Y.SellerFarPrace AND Y.BuyerSpread = Y.SellerSpreadAND Y.BuyerAmt = Y.SellerAmT) THEN DBO.GET_CUSTOMER_MNEMONIC(Y.SELLERID) Else Case When isnull(@p_Data_Show_Flag,1)=3 THEN DBO.GET_CUSTOMER_MNEMONIC(Y.SELLERId) Else '*' End End End, Y.SellerIdOther_Party_Id, Y.NearDateMain_Near_Dt, Y.FarDateMain_Far_Dt, Y.AmountsAmounts, Y.AmountAmount, Y.PricePrice, Y.DurationDuration, Y.SellerBroOther_Party_Bro, Y.BuyerBroMain_Party_Bro, Y.BuyerStateMain_Party_State, Y.SellerStateOther_Party_State, Y.BuyerNearPraceMain_Party_Near_Parse, Y.BuyerFarPraceMain_Party_Far_Parse, Y.BuyerSpreadMain_Party_Spread, Y.BuyerAmtMain_Party_Amt, Y.SellerNearPraceOther_Party_Near_Parse, Y.SellerFarPraceOther_Party_Far_Parse, Y.SellerSpreadOther_Party_Spread, Y.SellerAmtOther_Party_Amt, Y.LOCATION_CODE, Y.Buyer_Strike_StateMain_Party_Strike_State, Y.Seller_Strike_StateOther_Party_Strike_State, (DBO.GET_TRADEVISIONRR_TRADEVISIONID_CUST_STATUS('NY44', 18, Y.TradeVisionId,Y.TRADEVISION_VERSION ,'BUYER' )) Color_Value , 'CallMe_Btn_Value' = Case When Y.Buyer_Strike_State = 206 then 1000 Else 0 End from DBO.TradeVisionRR Y WHERE Y.LOCATION_CODE = @p_Location_Code AND Y.TRADEVISION_VERSION = (DBO.GET_TRADEVISIONRR_SET_MAX_VERSION('NY44', '02/05/2008', 169 ,Y.TradeVisionId )) AND Y.TRADEVISIONFILEID = 169 ------------------------------------------------------------ UNION ALL ------------------------------------------------------------ select Y.TradeVisionFileIdSET_ID, 'SELLER'Main_Party_Role, Y.TradeVisionId, Y.EntityId, Y.Done, Y.MatchDate, Y.SellerIdMain_Party_Id, 'BUYER_MNEMONIC' = Case When Y.Done = 1 THEN DBO.GET_CUSTOMER_MNEMONIC(Y.BUYERID) Else Case When (@p_Location_Code <> 'NY44' AND Y.BuyerState = 184AND Y.BuyerState = 184AND Y.IsBNearPraceTouched = 1 AND Y.IsSNearPraceTouched = 1 AND Y.IsBFarPraceTouched = 1AND Y.IsSFarPraceTouched = 1 AND Y.IsBSpreadTouched = 1 AND Y.IsSSpreadTouched = 1 AND Y.IsBAmtTouched = 1 AND Y.IsSAmtTouched= 1 AND Y.BuyerNearPrace = Y.SellerNearPrace AND Y.BuyerFarPrace = Y.SellerFarPrace AND Y.BuyerSpread = Y.SellerSpreadAND Y.BuyerAmt = Y.SellerAmT) THEN DBO.GET_CUSTOMER_MNEMONIC(Y.BUYERID) Else Case When isnull(@p_Data_Show_Flag,1)=3 THEN DBO.GET_CUSTOMER_MNEMONIC(Y.BUYERID) Else '*' End End End, DBO.GET_CUSTOMER_MNEMONIC(Y.SELLERID) SELLER_MNEMONIC, Y.BuyerIdOther_Party_Id, Y.NearDateMain_Near_Dt, Y.FarDateMain_Far_Dt, Y.AmountsAmounts, Y.AmountAmount, Y.PricePrice, Y.DurationDuration, Y.BuyerBroOther_Party_Bro, Y.SellerBroMain_Party_Bro, Y.SellerStateMain_Party_State, Y.BuyerStateOther_Party_State, Y.SellerNearPraceMain_Party_Near_Parse, Y.SellerFarPraceMain_Party_Far_Parse, Y.SellerSpreadMain_Party_Spread, Y.SellerAmtMain_Party_Amt, Y.BuyerNearPraceOther_Party_Near_Parse, Y.BuyerFarPraceOther_Party_Far_Parse, Y.BuyerSpreadOther_Party_Spread, Y.BuyerAmtOther_Party_Amt, Y.LOCATION_CODE, Y.Seller_Strike_StateMain_Party_Strike_State, Y.Buyer_Strike_StateOther_Party_Strike_State, (DBO.GET_TRADEVISIONRR_TRADEVISIONID_CUST_STATUS('NY44', 169, Y.TradeVisionId,Y.TRADEVISION_VERSION ,'SELLER' )) Color_Value , 'CallMe_Btn_Value' = Case When Y.Seller_Strike_State = 206 then 1000 Else 0 End from DBO.TradeVisionRR Y WHERE Y.LOCATION_CODE = @p_Location_Code AND Y.TRADEVISION_VERSION = (DBO.GET_TRADEVISIONRR_SET_MAX_VERSION('NY44', '02/05/2008', 169 ,Y.TradeVisionId )) AND Y.TRADEVISIONFILEID = 169 ) X where X.EntityId IN ( Select Distinct Entity_Id from Fn_Get_Allowed_Entity_List('NY44' , 169 , '02/05/2008' ,200000 )) and X.Main_Party_Id = 101901 Order By X.TradeVisionId
Help! I need to write a query that looks at one table with two columns. One column has 20K records and the second column has 25K records. I need to compare the two columns and pull out the difference between the two columns. The majority of the two columns data is the same but there are some that do not have a match between the two. The data is not in any current order. HELP! THANKS!
Hi, I need some help writing a query, and would rather not go into detail inside here. But if there is someone more advanced in SQL that could help me, could you please write me at g35gurl@yahoo.com. Thanks!
Hello, I have a database containing 2 tables: the first one called "weeks" has 4 columns: id, week number (ex: 2007/01), start date(ex:01/01/2007), end date(ex: 07/01/2007) the second one is called "tests" and has 5 columns: index, date, name, test name, duration
my goal: I want to make a query to get rows containing 3 columns: week number, name, dates = date1, date2, etc., tests=test1, test2, etc., total duration of test for the given week and given person
To be clear, I am trying to get per week a summary of names with the tests they did and how long total it lasted. The first tables is just here to get the week number, given the test date. My current query returns a list of all tests (table 2) with an added column of the week number and looks like this:
SELECT date, initials, test, [hours outside 8-19], [Week number] FROM tests, weeks WHERE date BETWEEN [start date] AND [end date]
What I need now is to have one line per person and per week with their total of hours for the week and the list of tests for the same week. I tried lots of things but does not know to get to my goal. Could someone please help me?
Any help will be appreciated. Thank you in advance
is there any better way of writing the below query. i don't want to use select again and again.. and as my table has millions of records.. can u pls.suggest me the best possible method.
Select comm_Name,comm_CreationDate, Total_Users = (Select count(*) from User_Community where UC_COMMID = comm_ID), New_Members = (Select count(*) from User_Community where convert(char(10),uc_timestamp,101) > CONVERT (char (10) ,'01/01/2008' ,101) and UC_CommID = COMM_ID) from Community
Database consists of the following 4 tables with respectiveattributes:CUSTOMER(C#, CUSTOMER NAME, ADDRESS), the key is [C#]ITEM(I#, ITEM NAME, MANUFACTURER, YEAR), the key is [I#]BOUGHT(C#, I#, DATE, QUANTITY), the key is [C#, I#,DATE]PREFER(I#, C#), the key is [I#, C#]I'm trying to construct the following query (in SQL)List of customers that bought all the items that John prefers.I can get the list of all the items that John prefers, but I'm notsure how to check that list against customers who bought ALL thoseitems. I'm assuming it's either a division or some sort of subtractionbut I'm not sure how to formulate the SQL query.Any and all help is appreciated, thanks!
Hello,I am trying to write a query and getting a little confused.My problem:I send enquiries to partners from 12:00am to 11:59pm each day. I have tenpartners, and each partner has a different daily limit. In my partner table(Table1), I have a columnm for the Daily Enquiry Limit called "DailyCap". Ialso have a second table (Table2) which counts how many enquiries a partnerhas had and assigns a date stamp.So, my query needs to:Select PARTNERwhere Table2.PartnerCount is less than Table1.DailyCapAND where Table2.TimeStamp between 12:00am TODAY and 11:59pm TODAY.This should hopefully then select any partner who hasent yet reached thedaily cap between midnight start and 24 hours later.Any odeas how to write this query using proper SQL? I have tried butfailed.Regards,Gary.