Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Friday, March 30, 2012

How Do I Add Time with integer value in MSSQL ?

Hi, Expert

How Do I Add Time with integer value in MSSQL ??

For Example: 07:00:50 + 20 = 07:01:10

Note: 20 is in second

Thanks in advance

Check out the DATEADD function in BOL (documentation).|||

Hi,

You can play with DATEADD function for your question, for example:

SELECT dateadd(s, 20, getdate())

this one will add 20 seconds to now.

You can look up this function from Books Online to find more information. By the way, in SQL Server there is datatime data type, but not time or date only data type.

Wednesday, March 28, 2012

How do I access a mdf-file directly?

Hello!
I want to access a sql server file without having sql server installed on my laptop. How can I do this? Can you give me an example please because I'm new with it.
Thx a lot!
TomI don't think this can be done. The closes you can get is to do a minimial installation, use the Personal Desktop edition. I don't think there is any tool our COM object that will allow one to open the file and read throuigh it.

If you need to analyse some data or tables you could export the data to MS Access, Excel or flat files.|||You will need to install either msde (I think) or sql server then you can do a sp_attach_single_file_db to access the database.|||I dont think that you would be able to do it.
But as suggested previously, you can try minimal installation and then get the data out in the format that you want.

Thanks|||hii
i think there is a microsoft desktop engine which minimally installs the components required by SQL. Try that that. i dont have info on that at the moment . will try to get u|||hii
Install MSDE which comes in the office 2000 Cd and Use SQL DMO object and attach it to the instance of MSDE. Try , it should work

:confused:

How do I .. use a dataview to break up sqldatareader ? Please Help!

Hello,

I am using a sqldatareader to get back a whole set of data.

The columns are id, data_id and data_desc

for example, the collection is
id data_id data_desc
0 100 this is name for id 0
0 101 this is address for id 0
0 102 this is gender for id 0
1 100 this is name for id 1
1 101 this is address for id 1
1 102 this is gender for id 1
2 100 this is name for id 2
2 101 this is address for id 2
2 102 this is gender for id 2
3 100 this is name for id 3
3 101 this is address for id 3
3 102 this is gender for id 3

I want to be able to go thru' this list and break up for each id and create a txt file. So, i will have four text files.

txt0.txt will contain
100, this is name for id 0
101, this is address for id 0
102, this is gender for id 0

I would like to know, how do i use a dataview to break up the sqldatareader so i can then repeat the loop for each id and generate the text file.

I don't have a problem generating the text file.

Please let me know, how should i go about it.

Thanks a bunch,
-Sean

If you are just looking to loop thru a SqlDataReader. Try this.

SqlCommand cmd = new SqlCommand("<Your query here>", con);
cmd.Connection.Open();
SqlDataReader dtrText = cmd.ExecuteReaderCommandBehavior.CloseConnection);
while(dtrText.Read())
{
//Write to text file here.
}
dtrText.Close();
con.Close();

Hope this helps.

Friday, March 23, 2012

How could I return the next row(Or 8th row for example)

Hi,
I want to return the next row in a select ... order by ... cursor.
I don't want to loop,just SQL,Do you know any solution?
For example: in Oracle we use rownum,is there any equivalent in SQL Server?
-ThanksWhy don't you explain why you think you need a cursor? In Oracle cursors are required, but with SQL Server they are considered inefficent and are rarely used.|||Thanks blindman ,
Typical scenario may be looks like this: I return the result of a heavy select(think about many joins and ...) to the client application: I want just one row at this stage. The application processes that row and then it needs the next row in that select to process.How should I say: "The next row in that select"?
One solution: Use a table (maybe temporary table) to hold the result of that select with an identity column as the rownum of each row.
Another solution: Hold the result of select in application layer and go through a loop in application to fetch the next row.
I am just curious about how one could do this in an "on the fly" manner? You are right maybe it is not efficient in SQL Server but is there any way at all?
-Regards|||Well, I think you should hold the data in the application layer if you want to ensure a static dataset for processing. Problem is, if you go back to SQL Server for your "next" record, the underlying data may have changed. Is your application modifying the data and sending it back to SQL server to be updated?|||Is your application modifying the data and sending it back to SQL server to be updated?
No,it is not.So there is no phantom read problem.I think this is so inefficient to pull all data to client-side only because you may want the next row.Are you in agreement? SQL Server should think about this carefuly,IMHO!
-Thanks|||Well you may think that, but it doesn't, not in SQL 2K.

2k5 will have rownumber if I'm not mistaken...

But this is the best server side paging articles I've seen

http://weblogs.sqlteam.com/jeffs/archive/2004/03/22/1085.aspx

And

http://weblogs.sqlteam.com/jeffs/archive/2003/12/22/672.aspx|||No,it is not.So there is no phantom read problem.I think this is so inefficient to pull all data to client-side only because you may want the next row.Are you in agreement? SQL Server should think about this carefuly,IMHO!
-Thanks
No, I'm not in agreement. How the data is displayed is up to the presentation layer and/or middle tier, and is not the database's responsibility. If the application demands paging, then the database needs to be DESIGNED to facilitate paging. Even ROWNUMBER is meaningless for repeated calls on dynamic datasets.|||How the data is displayed is up to the presentation layer and/or middle tier, and is not the database's responsibility.
OK,I am in agreement.Maybe this is about "Presentation of Data" but we know there is not a clear line between those layers: Many things can be done in Database layer but is implemented in "Application server or middle layer" and vice versa.
Thanks to your posts but I still think it is inefficient to pull whole data between layers and I became so happy when I heard that Yukon will have rownum from Brett.Thanks!|||I'd say use the system the way it was designed. Most of your time is not going to be pulling back an entire dataset, but cycling through it row by row. Databases are designed to work on results sets (i.e., not row by row) and thus aren't very efficient when you want to do that. However, procedural languages are designed to do that very thing. By way of example, I had a cursor running on the database when I first began posting here that took approximately 15 minutes to run. Through the help of those more knowledgable here, I was able to remove the cursor and get the same results in under 30 seconds. I guess the best way to test it is do it both ways, but I'm willing to bet you'll find that pulling the entire result set back and cycling in the app will be faster than coding a cursor in the database. Just my thoughts.

Wednesday, March 21, 2012

How change "Total" caption on hierarchy

Hello,

I want to change the "Total" Caption in hierarchy by "Total by Client" for example. I would know if is it possible or not? And how do this if it's possible.

Thanks,

Betty

Betty,

you want to rename the "All Level"? There is a property for that (in the dimension's properties "AttributeAllMemberName")...

sql

Monday, March 19, 2012

How can you deploy a simple report in a folder below the ReportServer?

Hello,
I would like to deploy report into folder named HOME3 located under the
ReportServer directory.
For example:
http://[hostname]/ReportServer/HOME3
How do I type in the TargetServerURL so that report is deployed in HOME3?
I appreciate the help. Thanks.
SteveHi, Steve
In " TargetFolder " enter HOME3 then deploy the report.
Angi
"steve kwon" <steven,kwon@.lmco.com> ¼¶¼g©ó¶l¥ó·s»D:ehmIW7RfFHA.3124@.TK2MSFTNGP12.phx.gbl...
> Hello,
> I would like to deploy report into folder named HOME3 located under the
> ReportServer directory.
> For example:
> http://[hostname]/ReportServer/HOME3
>
> How do I type in the TargetServerURL so that report is deployed in HOME3?
> I appreciate the help. Thanks.
> Steve
>

Wednesday, March 7, 2012

how can i use the " use " statement with database-name contains spaces in sql2000

example :

i cann't write :

use [my db]

what can i do with this problem ?

That works for me:

use [master]

CREATE DATABASE [Some DB]

USE [Some DB]

SELECT DB_NAME()

-

Some DB

(1 row(s) affected)

USE MASTER

DROP DATABASE [Some DB]

What error are you getting back ? Regardless of the possibiliy to put a space in the name, this is NOT recommended. It might work in the most cases but you will run in many cases where this isn′t supported (liek third party vendors)

HTH, Jens Suessmeyer.

Friday, February 24, 2012

How can I use arrays in parameters.

Following code is just select category 1 but for example What can I do if I
want to select 1 and 2?
declare @.CategoryID as int
set @.CategoryID = 1
SELECT * FROM Northwind.dbo.Products WHERE CategoryID in (@.CategoryID)Hi
You would need to use dynamic SQL to have multiple values in a IN clause
when using a variable number of values.
Regards
Mike
"Murat BUDAK" wrote:

> Following code is just select category 1 but for example What can I do if
I
> want to select 1 and 2?
> declare @.CategoryID as int
> set @.CategoryID = 1
> SELECT * FROM Northwind.dbo.Products WHERE CategoryID in (@.CategoryID)
>
>|||http://www.sommarskog.se/arrays-in-sql.html
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Murat BUDAK" <mbudak@.islem.com> wrote in message
news:u1J9jfuAFHA.1392@.tk2msftngp13.phx.gbl...
> Following code is just select category 1 but for example What can I do if
I
> want to select 1 and 2?
> declare @.CategoryID as int
> set @.CategoryID = 1
> SELECT * FROM Northwind.dbo.Products WHERE CategoryID in (@.CategoryID)
>|||"Mike Epprecht (SQL MVP)" <mike@.epprecht.net> wrote in message
news:96082D73-8AD1-4597-A0E6-55D9F16E4386@.microsoft.com...
> You would need to use dynamic SQL to have multiple values in a IN clause
> when using a variable number of values.
Mike,
You should read Erland's article that I posted the link to. You do not need
dynamic SQL for this.
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--|||Impresive. Thanks for this article :o)
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:Og0LJquAFHA.3492@.TK2MSFTNGP12.phx.gbl...
> http://www.sommarskog.se/arrays-in-sql.html
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Murat BUDAK" <mbudak@.islem.com> wrote in message
> news:u1J9jfuAFHA.1392@.tk2msftngp13.phx.gbl...
> I
>