Friday, March 30, 2012
ID Column has backed down !
honestly, i can't understand
why the pointer has backed down...
in design view, i see the value 147.720
while the last id-key is 147.772
what happens ?
thanks
atte, Hernn
You need to post your DDL so we can better understand the question. Are you
working with the identity property or is this a home-grown id?
--Brian
(Please reply to the newsgroups only.)
"bajopalabra" <bajopalabra@.hotmail.com> wrote in message
news:essjRIIuFHA.204@.TK2MSFTNGP10.phx.gbl...
> hi
> honestly, i can't understand
> why the pointer has backed down...
> in design view, i see the value 147.720
> while the last id-key is 147.772
> what happens ?
> thanks
> --
> atte, Hernn
>
ID Column has backed down !
honestly, i can't understand
why the pointer has backed down...
in design view, i see the value 147.720
while the last id-key is 147.772
what happens ?
thanks
atte, HernnYou need to post your DDL so we can better understand the question. Are you
working with the identity property or is this a home-grown id?
--Brian
(Please reply to the newsgroups only.)
"bajopalabra" <bajopalabra@.hotmail.com> wrote in message
news:essjRIIuFHA.204@.TK2MSFTNGP10.phx.gbl...
> hi
> honestly, i can't understand
> why the pointer has backed down...
> in design view, i see the value 147.720
> while the last id-key is 147.772
> what happens ?
> thanks
> --
> atte, Hernn
>
ID Column has backed down !
honestly, i can't understand
why the pointer has backed down...
in design view, i see the value 147.720
while the last id-key is 147.772
what happens ?
thanks
--
atte, HernánYou need to post your DDL so we can better understand the question. Are you
working with the identity property or is this a home-grown id?
--
--Brian
(Please reply to the newsgroups only.)
"bajopalabra" <bajopalabra@.hotmail.com> wrote in message
news:essjRIIuFHA.204@.TK2MSFTNGP10.phx.gbl...
> hi
> honestly, i can't understand
> why the pointer has backed down...
> in design view, i see the value 147.720
> while the last id-key is 147.772
> what happens ?
> thanks
> --
> atte, Hernán
>
Wednesday, March 21, 2012
I want to convert datetime value into MonthName.
In Page Body, there is a textbox whose value is in "mm/dd/yyyy" form. So I want it in "dd MonthName yy" format. How to do it.
Suppose the field name is field1 which has date in dd/mm/yyyy format, use this in the value expression
DatePart("dd", field1) & " " & MonthName(field1) & " " & DatePart("yy", field1)
|||It's acually even simpler than that.
In the format properties of the textbox enter in the Format Code: box (top left of tab)
dd MMMM yyyy to return a date such as 03 Novermber 2006
or
dd MMM yyyy to return a date such as 03 Nov 2006
Monday, March 19, 2012
i want a function like ifNull function to use in expression builder
Hi,
I wonder if there a function that i can use in the expression builder that return a value (e.g o) if the input value is null ( Like ifnull(colum1,0) )
i hope to have the answer because i need it so much.
Maylo
dont know if understood very well...
but....
You can use the function IIF(condition, TRUE, FALSE)
And can use IsEmpty function...
explain better!
Regards!
|||
Maylo wrote:
Hi,
I wonder if there a function that i can use in the expression builder that return a value (e.g o) if the input value is null ( Like ifnull(colum1,0) )
i hope to have the answer because i need it so much.
Maylo
Have you even opened up the expression builder in SSIS? Have you looked at the list of available functions on the right-hand side? Specifically the "NULL Functions" folder?
To answer your question, use: ISNULL(expression)
|||i try IIF(condition, TRUE, FALSE) and it said that IIF is not recognized ,
let me more clear in explaination
iam using Conditional Split Component and i want to be in its condition some like that Condition
( ( case ColumnX is null then zero else then ColumnX ) ==ColumnY )
then underline part is what i want to translate to a right experision to be used in the Conditional Split Component cases.
i hope you can help me soon
Best wishes
Maylo
|||
Maylo wrote:
i try IIF(condition, TRUE, FALSE) and it said that IIF is not recognized ,
let me more clear in explaination
iam using Conditional Split Component and i want to be in its condition some like that Condition
( ( case ColumnX is null then zero else then ColumnX ) ==ColumnY )
then underline part is what i want to translate to a right experision to be used in the Conditional Split Component cases.
i hope you can help me soon
Best wishes
Maylo
Yeah, Pedro wasn't on the right page for SSIS expressions.
This is what you want:
ISNULL([ColumnX]) ? 0 : [ColumnX]|||
Yeah you are right, I was thinking in SSAS...
Sorry... I was sleeping! :-)
Regards!
|||I want a default value of space
Are wrapping it in quotes?|||In testing, no matter what I do I cannot make SQL Server assign thedefault value of a single space or multiple spaces to a column. It always assigns an empty string. For reference, this is what Iam indicating for the default value:
(' ')
I thought it might have had to do with the varchar data type, so Ichanged it to char and had the same result. I am also stumped.
|||
It's nice to know I'm not alone. I'm doing the same - wrapping it in quotes. The problem is - it is interpreted as hex '00' when I move it to another string (which is part of a record I'm transmitting to a remote server) and this server can not handle NULL values. So unless I find a solution, I have to convert all with "empty-string" to " " before I send them. ouch.
If you find a solution, please let me know and I'll do the same.
Thanks,
John Pavelka
Monday, March 12, 2012
i think simple but tough for me Help
friend i had three columns in my crsytal report that shows values as
a = 1
b = 0
c shows nothing not 0 or some value as in database value of c = null
now i want
a+b+c using a formula
but it is not showing the output as null is their
please help out how can i get the result
as i want a+b+c = 1 should be output
if bychance the value of a= 1
b =1
c=0
then output s coming for sure
i.e 2
Hope u got my problem
How to add all the columns
With Best Regards
Rubyhi,
use the formula and palce ur fields in place of a,b and c. u will find the solution.
(IF ISNULL(a) THEN 0 ELSE a) + (IF ISNULL (b) THEN 0 ELSE b) +( IF ISNULL (c) THEN 0 ELSE c)
remeber in pryers.
online available at habibhussain82@.gmail.com|||Test if C is null before trying to add it. e.g.
if isnull({table.C}) then a+b
else a+b+c
I only get the first character of the field returned .. what am i doing wrong ?
here is my business/data object for some reason I only get the first character back, say value is Charlie, I only get C
public string GetUserName(long UserId) {try {string userName; DiscussionDB data =new DiscussionDB(); List paramlist =new List(); paramlist.Add(data.CreateParameter("@.UserId", UserId)); paramlist.Add(data.CreateParameter("@.UserName","", ParameterDirection.Output, DbType.String, 20)); data.ExecuteNonQuery("dbo.Discussion_User_Name",ref paramlist); userName = paramlist[1].Value.ToString();return userName; }catch {throw; } }ALTER PROCEDURE [dbo].[Discussion_User_Name]@.UserId bigint,@.UserName varchar(20) outputASSET NOCOUNT ONSET @.UserName = (Select [Name] from Discussion_Member WHERE UserID = @.UserID)if (@.UserNameis null or @.UserName ='')BEGIN SET @.UserName = (Select UserName from Membership_User WHERE UserID = @.UserID)END hello,
It does not seem that thre is anything wrong with the code.
Have you checked the size of the columns "Name" and "UserName" in Discussion_Member and/or Membership_User ?
hope this helps?
regards,
g
|||If you run the stored procedure using the sql server tools, does it return the correct result?
|||yes when I run the SP in MS sever 2005 studio, I get the full field ... e.g Charlie
|||You need to set the size of @.UserName, the default is 1. There's a size property toIDbDataParameter that you need to set (it looks like your DiscussionDB is wrapping IDbDataParameter and some other stuff)
|||I tried wording your suggestion in my code by I can't seem to figure it out
I was thinking that the 20in the code below was giving the size
paramlist.Add(data.CreateParameter("@.UserName","", ParameterDirection.Output, DbType.String, 20));
|||I thought I got this working but I was wrong
I am still having this issue, here is my last code
public string GetUserName(long UserId) {try {string userName; DiscussionDB data =new DiscussionDB(); List paramlist =new List(); paramlist.Add(data.CreateParameter("@.UserId", UserId)); paramlist.Add(data.CreateParameter("@.UserName","", ParameterDirection.Output, DbType.String, 15)); paramlist[1].Size = 15; data.ExecuteNonQuery("dbo.Discussion_User_Name_Fetch",ref paramlist); userName = paramlist[1].Value.ToString();return userName; }catch {throw; } }
Wednesday, March 7, 2012
i need to get the value of the max(date) of a table per person
Unique number
UserID
SitDate
Situation Int
I Need to get the last situation of the UserID
I'm stuck there with that query and it come out with the last for each
situation I only need the last situation.
Query:
SELECT DISTINCT MAX(DISTINCT SITUATION.SitDate) AS DateSit,
SITUATION.UserID, SITUATION.Situation
FROM SITUATION
GROUP BY SITUATION.PrevenuID,SITUATION.Situation
ORDER BY SITUATION.PrevenuID
Thanks for your help
EmmanuelJust a guess, and assumes that UserID/SitDate combo is "unique enough" (e.g.
includes time information). Please see http://www.aspfaq.com/5006 for help
on providing clear and complete requirements.
SELECT s.[Unique number],
s.UserID,
s.SitDate,
s.Situation
FROM
Situation s
INNER JOIN
(
SELECT UserID,
MAX(SitDate)
FROM Situation
GROUP BY UserID
) sub
ON
sub.UserID = s.UserID
AND s.SiteDate = sub.SiteDate;
"Emmanuel Vandal" <evandal@.videotron.com> wrote in message
news:Ft4Ef.46134$rX.677832@.weber.videotron.net...
>I got a table SITUATION with a userID, a date and a situation.
> Unique number
> UserID
> SitDate
> Situation Int
> I Need to get the last situation of the UserID
> I'm stuck there with that query and it come out with the last for each
> situation I only need the last situation.
> Query:
> SELECT DISTINCT MAX(DISTINCT SITUATION.SitDate) AS DateSit,
> SITUATION.UserID, SITUATION.Situation
> FROM SITUATION
> GROUP BY SITUATION.PrevenuID,SITUATION.Situation
> ORDER BY SITUATION.PrevenuID
> Thanks for your help
>
> Emmanuel
>|||Thank you, The "Unique enough" term just solve my problem, I generate many
data with a code that put the same date everywhere so the query was good but
the data not.
Emmanuel
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> a crit dans le
message de news: ujhUna0JGHA.3936@.TK2MSFTNGP10.phx.gbl...
> Just a guess, and assumes that UserID/SitDate combo is "unique enough"
> (e.g. includes time information). Please see http://www.aspfaq.com/5006
> for help on providing clear and complete requirements.
>
> SELECT s.[Unique number],
> s.UserID,
> s.SitDate,
> s.Situation
> FROM
> Situation s
> INNER JOIN
> (
> SELECT UserID,
> MAX(SitDate)
> FROM Situation
> GROUP BY UserID
> ) sub
> ON
> sub.UserID = s.UserID
> AND s.SiteDate = sub.SiteDate;
>
> "Emmanuel Vandal" <evandal@.videotron.com> wrote in message
> news:Ft4Ef.46134$rX.677832@.weber.videotron.net...
>
I need to find total for rows with a certain value: how?
and 0 for off, just those two values) and a date column which is a timestamp
containing a date and time. There are other columns in this table but they
are unimportant in this discussion.
A process inserts rows into this table about every second or so, depending
on the state of an object.
It has been requested of me that I prepare a report. Among other items,
this report must show the total time an object is turned on. In other
words, for every row that is set to 1, I need to add up the time and let the
users know how long that item was set to on for a given period of time, say
24 hours i.e. how long was that object in an on state during the last 24
hours.
I consider myself to be pretty handy at SQL but I must confess I'm at a loss
to come up with a query for this.
Any ideas and examples would be greatly appreciated?
Thanks in advance,
Chris SmithOh I neglected one important piece...
Select ObjectID, Sum(DateDiff(ms, On.LogDT, Off.LogDT)) OnTime
From LogTable On
Join LogTable Off
On Off.ObjectID = On.ObjectID
And Off.LogDT =
(Select Min(LofDT)
From LogTable
Where ObjectID = On.ObjectID
And LogDT > On.LogDT)
Where On.OnFlag = 1
And Off.OnFlag = 0
Group By ObjectID
"someone" wrote:
> I have a table that contains a column that collects discreet data (1 for o
n
> and 0 for off, just those two values) and a date column which is a timesta
mp
> containing a date and time. There are other columns in this table but the
y
> are unimportant in this discussion.
> A process inserts rows into this table about every second or so, depending
> on the state of an object.
> It has been requested of me that I prepare a report. Among other items,
> this report must show the total time an object is turned on. In other
> words, for every row that is set to 1, I need to add up the time and let t
he
> users know how long that item was set to on for a given period of time, sa
y
> 24 hours i.e. how long was that object in an on state during the last 24
> hours.
> I consider myself to be pretty handy at SQL but I must confess I'm at a lo
ss
> to come up with a query for this.
> Any ideas and examples would be greatly appreciated?
> Thanks in advance,
> Chris Smith
>
>|||jeez, typo... And this produces total Millliseconds, Change the ms inside
the datediff function to whatever you want it to produce if milliseconds is
not what you want:
sec, minute, hour, day, etc...
Select ObjectID, Sum(DateDiff(ms, On.LogDT, Off.LogDT)) OnTimeMs
From LogTable On
Join LogTable Off
On Off.ObjectID = On.ObjectID
And Off.LogDT =
(Select Min(LogDT)
From LogTable
Where ObjectID = On.ObjectID
And LogDT > On.LogDT)
Where On.OnFlag = 1
And Off.OnFlag = 0
Group By ObjectID
"someone" wrote:
> I have a table that contains a column that collects discreet data (1 for o
n
> and 0 for off, just those two values) and a date column which is a timesta
mp
> containing a date and time. There are other columns in this table but the
y
> are unimportant in this discussion.
> A process inserts rows into this table about every second or so, depending
> on the state of an object.
> It has been requested of me that I prepare a report. Among other items,
> this report must show the total time an object is turned on. In other
> words, for every row that is set to 1, I need to add up the time and let t
he
> users know how long that item was set to on for a given period of time, sa
y
> 24 hours i.e. how long was that object in an on state during the last 24
> hours.
> I consider myself to be pretty handy at SQL but I must confess I'm at a lo
ss
> to come up with a query for this.
> Any ideas and examples would be greatly appreciated?
> Thanks in advance,
> Chris Smith
>
>|||I assume that the table also contains an ObjecID - to identofy WHICH Object
is being Tuened On Or OFF...
Select ObjectID, Sum(DateDiff(ms, On.LogDT, Off.LogDT)) OnTime
From LogTable On
Join LogTable Off
On Off.ObjectID = On.ObjectID
And Off.LogDT =
(Select Min(LofDT)
From LogTable
Where ObjectID = On.ObjectID
And LogDT > On.LogDT)
Group By ObjectID
"someone" wrote:
> I have a table that contains a column that collects discreet data (1 for o
n
> and 0 for off, just those two values) and a date column which is a timesta
mp
> containing a date and time. There are other columns in this table but the
y
> are unimportant in this discussion.
> A process inserts rows into this table about every second or so, depending
> on the state of an object.
> It has been requested of me that I prepare a report. Among other items,
> this report must show the total time an object is turned on. In other
> words, for every row that is set to 1, I need to add up the time and let t
he
> users know how long that item was set to on for a given period of time, sa
y
> 24 hours i.e. how long was that object in an on state during the last 24
> hours.
> I consider myself to be pretty handy at SQL but I must confess I'm at a lo
ss
> to come up with a query for this.
> Any ideas and examples would be greatly appreciated?
> Thanks in advance,
> Chris Smith
>
>|||It might be helpful for you to provide sample data, especially about
this timestamp field. When a row is inserted with the on/off flag set
to ON, what value is in the timestamp column? The way I see it, there
are 3 options: -
1. The time the object entered the ON state only
2. The time the object left the ON state only
3. Both the time the objected entered the ON state + the time it left
or the duration it was in this state.
The 3rd option is easy because all you need to do is sum the duration
(or calculate it from the Left - Entered Time and sum) for each state
in a given time period.
The 1st and 2nd options are a bit tough since you have to form a sort
of JOIN to find the related state from which the object toggled from or
to. e.g. if I store the time the object entered the ON state, to find
out how long it stayed in this state, I need to find the immediate NEXT
time it entered the OFF state. Likewise, if it is the end time that is
stored, I need to find the immediate PREVIOUS time it left the OFF
state.
Another thing you will have to consider, though this has to do with
data integrity, how do u ensure no overlaps occur in the records (such
that your data says at a given point in time, the object was both ON
and OFF)? Do you allow time gaps in which you can't tell whether the
object was ON or OFF? if you don't how do u ensure there are no gaps?
If you do, how do you interpret the time where there are no records?
Please clarify...|||It might be helpful for you to provide sample data, especially about
this timestamp field. When a row is inserted with the on/off flag set
to ON, what value is in the timestamp column? The way I see it, there
are 3 options: -
1. The time the object entered the ON state only
2. The time the object left the ON state only
3. Both the time the objected entered the ON state + the time it left
or the duration it was in this state.
The 3rd option is easy because all you need to do is sum the duration
(or calculate it from the Left - Entered Time and sum) for each state
in a given time period.
The 1st and 2nd options are a bit tough since you have to form a sort
of join to find the related state from which the object toggled from or
to. e.g. if I store the time the object entered the ON state, to find
out how long it stayed in this state, I need to find the NEXT time it
entered the OFF state. Likewise, if it is the end time that is stored,
I need to find the PREVIOUS time it left the OFF state.
Another thing you will have to consider, though this has to do with
integrity, how do u ensure no overlaps occur in the records? Do you
allow time gaps in which you can't tell whether the object was ON or
OFF? if you don't how do u ensure there are no gaps? If you do, how do
you interpret the time where there are no records?
Please clarify...|||Hi Sienko,
I'll try to answer your questions as best as I can.
First of all, it should be noted this isn't a typical database. This is
actually a database accessed through MS SQL 2000 called InSQL. InSQL allows
you to store real time data more efficiently than SQL Server while allowing
for more transactions per second and storing the data in a manner that
allows for smaller files on the harddrive than what SQL Server itself would
allow. InSQL itself is actually made up of extension tables to SQL Server
2000. Along with this, InSQL provides other things such as providing a
discreete data type which allows you to store values that tells you if a
device is on or off where 1=on/open and 0=off/close. This probably isn't
important for you to know but it might be. For the most part, T-SQL is
still valid so any solution you can help me find should still work.
A typical row will include a column for a tagname, a discreete value column
(contains a value of 1 or 0, that is all as far as I know of), and a
timestamp which is just a datetime column (this column is equal to the time
the discreete value was retrieved from a device, not the time the row was
created). There are other columns but they aren't important to this
discussion as far as I know of. An example row might look like:
tagname_here -- discreete value -- datetime
There are rows inserted for each tag about every second or so. We'll say a
row is inserted each second to keep this simple. The rows will be the same,
just the fact the discreete value is different along with the time. For
example, a valve maybe open at the time a sensor takes a reading so this
data is retrieved (the state of the valve along with the datetime the
reading was taken) and inserted into a table (discreetehistory is the name
of the table I think, we'll use that for the sake of this conversation). As
long as the valve is open, a row will be inserted into this table where that
row will have a 1 in the discreete column and the datetime that value was
taken. When the valve is closed, rows will be inserted into the table where
the discreete value is now 0 and it has a datetime with it. Again, as long
as the valve is closed, rows will be inserted into the table with a
discreete value of 0 along with it's datetime. In other words, we have a
process that is looking at equipment 24/7/365. This process determines the
state of devices and inserts rows into a table every second or so.
Everytime a row is written, that row represents the state of the device and
a datetime is stored in that row to let us know when the sensor reading was
taken.
I don't think the table will allow null values nor do I believe a null value
will ever occur but am not certain. There is a transition period between
opening and closing valves. After all, a valve doesn't instantly open or
close. Depending on the size of size valve, it might take 1 to 5 seconds to
switch states. But, I don't believe this transition state is being
recorded. I wish I was at work answering this. I could tell you for sure
then.
Again, the problem is I need a query where I can report how long a valve was
left open in the last two hours. In other words, for a time from 12:00PM to
2:00 PM, the valve might be open at first but close at 12:30. Then, the
valve might open at 12:40. Then, the valve might be close at 1:00PM and
then open again at 1:10 PM. In other words, the valve was opened and
closeded multiple times during this two hour block. In total, the valve was
open 1hr and 40 minutes during this two hour block with the valve being
closed for 20 minutes. I need a query that will read this table and
everytime the valve is open which is represented with a discreete value of 1
(where 1 = open), then it will sum up all the times and report this to me.
I thought I was pretty good with T-SQL but I've never done anything like
this before when it comes to time. I must admit I don't have the slightest
idea how to proceed with this one.
Any thoughts would be greatly appreciated. If you need more information,
please let me know.
Thanks for trying to help me out. I apologize for taking a while to respond
to you but I was busy and simply forgot about this.
Thanks again!
Chris Smith
"sienko" <sienko@.gmail.com> wrote in message
news:1112174062.024672.131620@.g14g2000cwa.googlegroups.com...
> It might be helpful for you to provide sample data, especially about
> this timestamp field. When a row is inserted with the on/off flag set
> to ON, what value is in the timestamp column? The way I see it, there
> are 3 options: -
> 1. The time the object entered the ON state only
> 2. The time the object left the ON state only
> 3. Both the time the objected entered the ON state + the time it left
> or the duration it was in this state.
> The 3rd option is easy because all you need to do is sum the duration
> (or calculate it from the Left - Entered Time and sum) for each state
> in a given time period.
> The 1st and 2nd options are a bit tough since you have to form a sort
> of JOIN to find the related state from which the object toggled from or
> to. e.g. if I store the time the object entered the ON state, to find
> out how long it stayed in this state, I need to find the immediate NEXT
> time it entered the OFF state. Likewise, if it is the end time that is
> stored, I need to find the immediate PREVIOUS time it left the OFF
> state.
> Another thing you will have to consider, though this has to do with
> data integrity, how do u ensure no overlaps occur in the records (such
> that your data says at a given point in time, the object was both ON
> and OFF)? Do you allow time gaps in which you can't tell whether the
> object was ON or OFF? if you don't how do u ensure there are no gaps?
> If you do, how do you interpret the time where there are no records?
> Please clarify...
>|||You usually model time as durations, so you would have
CREATE TABLE Events
(event_id CHAR(10) NOT NULL,
start_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
end_time DATETIME, -- null means current
. );|||On Sat, 2 Apr 2005 12:49:01 -0500, someone wrote:
-- Crosspost to non-existant group removed --
(snip description)
>I thought I was pretty good with T-SQL but I've never done anything like
>this before when it comes to time. I must admit I don't have the slightest
>idea how to proceed with this one.
>Any thoughts would be greatly appreciated. If you need more information,
>please let me know.
Hi Chris,
I think the best way to approach this problem is to start with a view to
reduce the load of imported data to just the relevant things: periods
without status change, with beginning and ending datetime.
CREATE VIEW Periods
AS
SELECT start.Status,
start.TheDatetime AS StartDT,
MAX(sameperiod.TheDatetime) AS EndDT
FROM RawData AS start
INNER JOIN RawData AS sameperiod
ON sameperiod.Status = start.Status
AND sameperiod.TheDatetime >= start.TheDatetime
AND NOT EXISTS
(SELECT *
FROM RawDate AS beetween -- deliberate misspelling: reserved word
WHERE beetween.TheDatetime > start.TheDatetime
AND beetween.TheDatetime < sameperiod.TheDatetime
AND beetween.Status <> start.Status)
WHERE NOT EXISTS
(SELECT *
FROM RawDate AS previous
WHERE previous.TheDatetime =
(SELECT MAX(TheDatetime)
FROM RawData
WHERE TheDatetime < start.TheDatetime)
AND previous.Status = start.Status)
GROUP BY start.Status, start.TheDatetime
With this query, your report becomes easy:
DECLARE @.StartReport smalldatetime
DECLARE @.EndReport smalldatetime
SET @.StartReport = '2005-04-02T12:00:00'
SET @.EndReport = '2005-04-02T14:00:00'
SELECT SUM(DATEDIFF(minute,
CASE WHEN StartDT < @.StartReport
THEN @.StartReport ELSE StartDT END,
CASE WHEN EndDT < @.EndReport
THEN @.EndReport ELSE EndDT END))
FROM Periods
WHERE StartDT < @.EndReport
END EndDT > @.BeginReport
I was not able to test the query and view above, since you have not
posted the CREATE TABLE and INSERT statements needed to create a test
database on my server.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||The thing is I'm not creating a table with multiple columns for dates. A
table is already present with one datecolumn only. I need to find all rows
within a timespan that have a value equal to 1 in the discreete value
column. Once I find all the rows, I need to add them all somehow such that
it will tell me the total time all the rows were set to a 1 in this column.
Any ideas on that?
Thanks!
Chris Smith
"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1112464694.412138.243320@.o13g2000cwo.googlegroups.com...
> You usually model time as durations, so you would have
> CREATE TABLE Events
> (event_id CHAR(10) NOT NULL,
> start_time DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
> end_time DATETIME, -- null means current
> .. );
>
Friday, February 24, 2012
I need help...!
I am using IN to determine if a given StateId values matches any value in a
query.
Previously, I used following query:
SELECT * FROM Cities WHERE StateId IN (1, 2, 3)
but now I would like to pass dynamic values as a input parameter...
SELECT * FROM Cities WHERE StateId IN(@.StateId)
StateId is an integer.
Could anyone help me with this, I can't get it working. I am new to SQL
Server.
Thank you!
JamesJames
CREATE PROCEDURE mysp
@.array nvarchar(4000)
AS
BEGIN
SET NOCOUNT ON
DECLARE @.nsql nvarchar(4000)
SET @.nsql = '
SELECT *
FROM sysobjects
WHERE name IN ( ' + @.array + ')'
PRINT @.nsql
EXEC sp_executesql @.nsql
END
GO
EXEC mysp
@.array = '''sysobjects'',''sysindexes'',''syscolu
mns'''
GO
"James T." <gimenei@.hotmail.com> wrote in message
news:O7P%23D8dOFHA.3356@.TK2MSFTNGP12.phx.gbl...
> Hello!
> I am using IN to determine if a given StateId values matches any value in
a
> query.
> Previously, I used following query:
> SELECT * FROM Cities WHERE StateId IN (1, 2, 3)
> but now I would like to pass dynamic values as a input parameter...
> SELECT * FROM Cities WHERE StateId IN(@.StateId)
> StateId is an integer.
> Could anyone help me with this, I can't get it working. I am new to SQL
> Server.
> Thank you!
> James
>|||The Curse and Blessings of Dynamic SQL
http://www.sommarskog.se/dynamic_sql.html
Arrays and Lists in SQL Server
http://www.sommarskog.se/arrays-in-sql.html
Faking arrays in T-SQL stored procedures
http://www.bizdatasolutions.com/tsql/sqlarrays.asp
How do I simulate an array inside a stored procedure?
http://www.aspfaq.com/show.asp?id=2248
AMB
"James T." wrote:
> Hello!
> I am using IN to determine if a given StateId values matches any value in
a
> query.
> Previously, I used following query:
> SELECT * FROM Cities WHERE StateId IN (1, 2, 3)
> but now I would like to pass dynamic values as a input parameter...
> SELECT * FROM Cities WHERE StateId IN(@.StateId)
> StateId is an integer.
> Could anyone help me with this, I can't get it working. I am new to SQL
> Server.
> Thank you!
> James
>
>
I need help with stored procedures.
Basically I've got a stored procedure, and I want to declare a variable within that stored procedure then put a value into that varible with a SELECT statement , then INSERT that value, along with some other values, into another table. I hope im explaining myself right.
Anyway, here's my code (its wrong)
/*
This stored procedure adds a new issue
*/
CREATE PROCEDURE {databaseOwner}{objectQualifier} [PreciseData_IssueTracker_AddIssue]
@.moduleId int,
@.starterUserId int,
@.typeId int,
@.subject varchar (50)
AS
SET @.assignedUserId = SELECT userId FROM PreciseData_IssueTracker_Assignments WHEREtypeId=@.typeId
INSERT INTO PreciseData_IssueTracker_Issue
(
moduleId,
starterUserId,
assignedUserId,
statusId,
typeId,
subject,
startDate
)
VALUES
(
@.moduleId,
@.starterUserId,
@.assignedUserId,
1,
@.typeId,
@.subject,
getdate()
)
GO
SELECT @.assignedUserId = userId FROM PreciseData_IssueTracker_Assignments WHEREtypeId=@.typeId
|||Thanks very much!