|
Ok so you can't merge the fields in anyway. Does anyone else know?
|
|
|
|
|
Hi
You can write your sub-query in a separate function. (table-valued function). Using this function, you can join with the main query as given below.
Select Col1, Col2, dbo.Fn_SubQuery(param1,param2)
from Table1
Hope this helps.
See the example below
<br />
use northwind<br />
go<br />
create function dbo.Fn_OrdersProductID(@OrderID int)<br />
returns nvarchar(4000)<br />
as <br />
begin<br />
DECLARE @ProductID nvarchar(4000)<br />
set @ProductID = null <br />
SELECT @ProductID = COALESCE(@ProductID + ',','') + cast(ProductID as nvarchar)<br />
FROM [Order Details]<br />
WHERE OrderID = @OrderID<br />
<br />
RETURN @ProductID<br />
<br />
end<br />
<br />
-- run the foll. stmt after executing the above function<br />
-- SELECT OrderID,dbo.Fn_OrdersProductID(OrderID) from Orders
Apply the same for your query
-- modified at 7:08 Tuesday 3rd July, 2007
-- modified at 7:11 Tuesday 3rd July, 2007
Harini
|
|
|
|
|
what is the need of COALESCE
|
|
|
|
|
Harini is right I believe.
Something like:
SELECT DISTINCT
IH.InvoiceDate AS HistoryDate
, 'Part of Invoice' AS HistoryType
, SI.SiteName AS HistoryBranch
, ('Invoice Number - ' + IH.InvoiceNumber + ' - ' + C.CustomerForeName + ' ' + C.CustomerSurname) AS HistoryReference
, getInvoicePhoneIMEIs(IH.InvoiceID) AS HistoryIMEIs
FROM tblInvoiceHeader IH
INNER JOIN tblInvoiceItems II ON II.InvoiceID = IH.InvoiceID
INNER JOIN tblSites SI ON IH.SiteID = SI.SiteID
INNER JOIN tblStaff ST ON IH.StaffID = ST.StaffID
LEFT JOIN tblCustomers C ON IH.CustomerID= C.CustomerID
WHERE II.StockID = '1750'
AND IH.InvoiceDate >= 'January 1, 2007'
AND IH.InvoiceDate <= 'July 2, 2007'
AND IH.SiteID = '10'
AND IH.InvoiceProForma = 0
where getInvoicePhoneIMEIs(IH.InvoiceID) uses a cursor based on your subselect to build a string.
http://www.sqlteam.com/article/using-coalesce-to-build-comma-delimited-string[^]
Be sure to include the DISTINCT keyword or you'll get a result row for every InvoicePhoneIMEI value.
David
|
|
|
|
|
I want to disable the dbo schema in my Database.
I want to disable the windows authontication users
merwa
|
|
|
|
|
Great. Now where is your code for us to review?
______________________
stuff + cats = awesome
|
|
|
|
|
You really cannot disable or rename the dbo schema. You cannot disable Windows Authentication entirely - the options are either Windows Authentication, or Mixed Mode which is both Windows Authentication and SQL Server Authentication.
You can delete the BUILTIN\Administrators login (I think, but I'm not willing to try it - back up your master database first and make sure you have another login in the sysadmin role, or have SQL Server authentication enabled and know your sa password). You can certainly change that login from a GRANT to a DENY, but I think that will have the effect of denying access to anyone in the Administrators group even if they would be GRANTed access through another login.
However, Windows Authentication is generally considered Best Practice as the account details are not stored in the SQL Server database server itself (SQL Server login passwords are stored in master ), and therefore cannot be compromised through SQL Server itself. Also, before SQL Server 2005, SQL Server passwords were passed in the clear - anyone with a network sniffer can see the passwords. SQL Server 2005 Native Client and .NET Framework 2.0 support encrypted connections, IIRC.
If you're not talking about allowing Administrators to have access you will find any other logins under Security\Logins in Enterprise Manager or Management Studio.
|
|
|
|
|
I have a table Tab1 with fields Name and Dt( data type Date/Time).
the col Dt have values
2/2/2007
3/3/2007
5/5/2008
i want to display names with date before 1/1/2008
i wrote the folowing query
"SELECT Name from tab1 where dt < 1/1/2008"
but this returns nothing..
iam using msaccess 2003.
thanks
|
|
|
|
|
I think in Access you have to surround date/time literals with the # sign. Try:
"SELECT Name from tab1 where dt < #1/1/2008#"
|
|
|
|
|
|
Hello there,
the correct query is here
SELECT Name from tab1 where dt < #1/1/2008#
Rahul Goel
Microsoft Cerfied Solution Developer .Net
Contact me at : rahul.g2510@gmail.com
|
|
|
|
|
Our application is running successfully on production server from last three month. Yesterday we received the error - Timeout Error: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Our application is built in asp.net 2.0 and Sql server 2000. We are importing a large set of data in database using transaction object of ado.net. When I ran the same application on test database with same set of files I didn’t received any error. The problem is with sql server on production. We don’t want to set the time out property of command object. Can any one suggest me some solution?
Saurav
|
|
|
|
|
My first guess would be you need look at both your production database and your test database. I would guess that your test database perhaps doesn't have as many records as your prod database. If you prod database has a lot of records it can take longer to insert records. Especially if you have lots of keys or indexs in prod that you don't have in test.
I have found with large import systems, sometimes the best thing to do is to let the web site queue it up and then have something like a windows service process the files. This will keep you from having to worry about any web site timeouts.
In the end you may have to increase your transaction object timeout.
One last thing you can check, when an import is running check the prod server to see if some other process is blocking it. You can do this by running sp_who or sp_who2
Hope that helps.
Ben
|
|
|
|
|
hi,
i am tired searching the net for this solution,
i may b using the wrong query to find my solution..
i finally came here hope anyone can help me,and that i have posted my question in the proper frame
my question is ,
i would like to write an sql query to display data from two table found in my database,in a single table in the asp page..
plz help
thanks
|
|
|
|
|
data from 2 tables in a database and display it as single table in asp page.
You have to joins! Use inner join and join the two tables accordingly!
Gautham
|
|
|
|
|
I want to add a column in a table using dynamic query.
e.g
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[SP_InsertColumnToAudience]
@ColumnName varchar(50)
as
set nocount on
declare @qry varchar(250)
begin
set @qry='alter table tblAudience add aaa1aa varchar(100) NULL'
exec @qry
end
but it gives error........
any sugession........
Do good and have good.
|
|
|
|
|
|
Hi,
I need to read/write the flat files from oracle, as i have read some article saying that we can do it thru utl_file. I have created a directory in oracle as
Create directory oraload as 'c:\oraload'
As i have got a sample which is compiling by when executing its giving a error saying invalid file operation.
create or replace
PROCEDURE create_cmd_file IS
DirLoc VARCHAR2(30) := 'ORALOAD';
DayFile utl_file.file_type;
LogFile utl_file.file_type;
vErrMsg VARCHAR2(250):='WRITE CHECKUP';
vMessage VARCHAR2(250):='BY RAVINDRA';
BEGIN
DayFile := utl_file.fopen(DirLoc, 'execsqlldr.ksh','W');
LogFile := utl_file.fopen(DirLoc, 'log_list.dat','W');
utl_file.putf(dayfile, '%s\n',vErrMsg);
utl_file.putf(Logfile,'%s\n',vMessage);
utl_file.fclose(DayFile);
utl_file.fclose(LogFile);
EXCEPTION
WHEN OTHERS THEN
vErrMsg := SQLERRM;
vMessage := 'DailyLoad CREATE_CMD_FILE Failed With ERROR ' || vErrMsg;
DBMS_OUTPUT.PUT_LINE ('dba@psoug.org' || 'SQL Loader Failure Notification' || vMessage);
END create_cmd_file;
Ravi
|
|
|
|
|
I haven't used UTL_FILE for several years - but I do remember that you have to add a "UTL_FILE_DIR" configuration value to the .ORA file to specify the list of folders that UTL_FILE operations can access.
|
|
|
|
|
Yah, i know it will in be init.ora file, but i couldn't able to find this file any where in my directory, could you pls provide me the location of this file and the content to be changed.
Ravi
|
|
|
|
|
hi
How to get difference between time
i.e column1 have some start time
and column2 have some finish time
difference between column1 and column2?
|
|
|
|
|
Look in the online-help for the datediff function.
|
|
|
|
|
Are you looking for this[^] ?
Happy Programming
|
|
|
|
|
DATEDIFF() function accepts two DATETIME values and a date portion (minute, hour, day, month, and so on) as parameters. DATEDIFF() determines the difference between the two date values passed, expressed in the date portion specified
Regards
SG (sgg245@yahoo.co.in)
|
|
|
|
|
hi
then what should be the data type of that column, so that i can save time only.
bec
in my requirement i have requested any department for a request. so at what time they received my request and what time they have replayed me i.e i want to calculate how much time taken to complete my request
thanks
alisha
|
|
|
|